一个例子,其中参考了emu画线的代码
<script>
lastx=400;lasty=300;color="red";lastline="";
document.onclick=drawline;
function drawline()
{
x0=lastx;
y0=lasty;
x1=event.clientX;
y1=event.clientY;
rs="";
if (y0 == y1)  //画横线
{
if (x0>x1){var t=x0;x0=x1;x1=t}  
rs = "<span style='top:"+y0+";left:"+x0+";position:absolute;font-size:1px;background-color:"+color+";height:1; width:"+Math.abs(x1-x0)+"'></span>";
}
else if (x0 == x1)  //画竖线
{
if (y0>y1){var t=y0;y0=y1;y1=t} 
rs = "<span style='top:"+y0+";left:"+x0+";position:absolute;font-size:1px;background-color:"+color+";width:1;height:"+Math.abs(y1-y0)+"'></span>";
}
else
{
var lx = x1-x0
var ly = y1-y0
var l = Math.sqrt(lx*lx+ly*ly)
rs = new Array();
for (var i=0;i<l;i+=1)
{
var p = i/l;
var px = parseInt(x0 + lx*p);
var py = parseInt(y0 + ly*p);
rs[rs.length] = "<span style='top:"+py+";left:"+px+";height:1;width:1;position:absolute;font-size:1px;background-color:"+color+"'></span>";
}
rs = rs.join("");
}
div1.innerHTML=lastline+rs;lastx=x1;lasty=y1;lastline=div1.innerHTML;
}
</script>
<body onload="document.all.begindot.top=lasty;document.all.begindot.left=lastx;">
begin<span id=begindot style="position:absolute;background:red,height:1px;width:1px"></span>
<div id=div1></div>