javascript通过表格绘制颜色填充矩形
<html> <head> <title> Javascript画矩形 </title> <script type="text/javascript"> //定义函数,传入设置参数,返回一个有背景颜色的表格 function drawFilledRect(x,y,w,h,color) { document.write("<table border='0' cellspacing=0 cellpadding=0><tr><td style='position: absolute; left: "+(x)+"; top: "+(y)+";background-color: "+color+"' width="+(w)+" height="+(h)+"></td></tr></table>") } </script> </head> <body > <script type="text/javascript"> //调用两次画矩形的函数 drawFilledRect(20,80,100,100,"red"); drawFilledRect(20,180,100,100,"lime"); </script> </body> </html>