onreadystatechange = function(){ # 重写回调函数 if(req.readyState == 4 && req.status == 200){ var text = req.responseText; # 响应的字符串 }}
localStorage
Worker
介绍
it is a javascript running in the background, without affecting the performance of the page.
dom中的js线程在执行时会阻塞
使用
var w;// start workerfunction startWorker(){ if(typeof(Worker) !== 'undefined'){ if(typeof(w) == 'undefined'){ w = new Worker('demo_workers.js'); } w.onmessage = function(event){ # worker 's api, will call postMessage() document.getElementById('result').innerHTML = event.data; }; }else { document.getElementById('result').innerHTML = 'sorry, your browser does not support Web Workers...'; }}// stop workerw.terminate(); # worker 's api, will trigger w.onmessage();w = undefined;/* demo_workers.js */ # 外部的js文件不能访问window, document, parent对象var i = 0;function timeCount(){ i = i + 1; postMessage(i); # worker 's api, when onmessage() was triggered. setTimeout('timeCount()', 500);}timedCount();
EventSource
介绍
浏览器推送
事件
onopen
onmessage
onerror
使用
var source = new EventSource("demo_sse.php");source.onmessage = function(event){ document.getElementById('result').innerHTML += event.data + '<br/>';};// demo_sse.php<?phpheader('Content-Type: text/event-stream');header('Cache-Control: no-cache');$time = date('r');echo "data: The server time is: {$time}\n\n"; # data在上面event.data中引用flush();?>
控件
ActiveXObject
new ActiveXObject(“Excel.Application”); # Microsoft.XMLHTTP, ie中适用
Server.CreateObject(“Microsoft.XMLHTTP”) # 在chrome中不起作用, 可以用 new XMLHttpRequest()创建
canvas
概念
原点: canvas左上角
默认Style为black
颜色设定
“red” “blue”
"#EEEEFF"
“rgb(1-255, 1-255, 1-255)”
“rgba(1-255, 1-255, 1-255, 0-1)”
路径
可以被填充多个轮廓或图形的操作。
基本使用
var context =canvas.getContext(“2d”);
context.fill()//填充
context.stroke()//绘制边框
context.lineWidth//图形边框宽度
context.fillStyle//填充的样式
context.strokeStyle//边框样式
绘制
矩形
content.fillRect(x, y, width, height)
strokeRect(x, y, width, height) # x, y是起点坐标, width, height为宽和高
清除矩形区域
context.clearRect(x,y,width,height)
圆弧
context.arc(x, y, radius, startAngle,endAngle, anticlockwise)