var canvas=document.getElementById('canvas');
var ctx =getContext('2d');
ctx.beginPath();
ctx.lineWidth=1;
ctx.strokeStyle="#000";
ctx.rect(0,0,10,20);
ctx.stroke();
ctx.closePath();
//用closepath结束绘画,否则可能出现黏连;
ctx.beginPath();
ctx.lineWidth=1;
ctx.strokeStyle="#f00";
ctx.rect(50,0,10,20);
ctx.stroke();
ctx.closePath();
用moveTo(x,y)和lineTo(x1,y1)就可以。