javascript implements the method of filling rectangles with color by drawing a table
- 2020-05-30 19:29:10
- OfStack
The example in this article describes how javascript implements a color-filled rectangle drawn by a table. Share with you for your reference. The details are as follows:
<html>
<head>
<title> Javascript Draw a rectangular </title>
<script type="text/javascript">
// Define the function, pass in the Settings parameter, and return 1 A table with a background color
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">
// Call the function that draws the rectangle twice
drawFilledRect(20,80,100,100,"red");
drawFilledRect(20,180,100,100,"lime");
</script>
</body>
</html>
I hope this article has been helpful to your javascript programming.