Home > Web Front-end > JS Tutorial > body text

Javascript method to draw color-filled rectangle through table_javascript skills

WBOY
Release: 2016-05-16 16:02:48
Original
1273 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template