The example in this article describes the method of using JavaScript to draw a color-filled rectangle through a table. Share it with everyone for your reference. The details are as follows:
<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>
I hope this article will be helpful to everyone’s JavaScript programming design.