用直线画出的矩形
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type="text/css"> canvas{ background-color: red; } </style> </head> <body> <canvas id="myCanvas" height="800" width="800"/> </body> <script type="text/javascript"> var c=document.getElementById("myCanvas"); var cxt=c.getContext("2d"); cxt.lineTo(100,0);//用直线话的矩形 cxt.lineTo(100,100); cxt.lineTo(0,100); cxt.stroke(); </script> </html>