绘图脚本语法错误(JavaScript)

时间:2011-04-09 02:19:06

标签: javascript

我正在为我的班级(javascript)编写一个程序,它只是在画布上绘制线条。并使用alt键绘制白色并使其外观为“Erased”。我完成了代码,但是我遇到了语法错误,无法看到我做错了什么。你能帮忙吗?

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Simple Drawing Program</title>

 (Assignment 7a)<br /><hr />
<style type = "text/css"> 
    #canvas { width: 400px; 
              border: 1px solid #999999; 
              border-collapse: collapse} 
    td      { width: 4px; 
              height: 4px } 
    th.key  { font-family: arial, helvetica, sans-serif;
              font-size: 12px; 
              border-bottom: 1px solid #999999 } 
  </style> 
  <script type = "text/javascript">
    <!-- 
    // initialization inserts cells into the table 
    function createCanvas () 
      var side = 100; 

      var tbody = document.getElementById ("tablebody"); 

      for (var i = 0; i < side; i++) 
      { 
        var row = document.createElement ("tr"); 

        for (var j = 0; j < side; j++) 
        { 

          var cell = document.createElement ("td"); 

          cell.onmousemove = processMouseMove;
          row.appendChild (cell);
        }
        tbody.appendChild (row);
      }
    }

    // draws when mouse is moved by turning cells red or blue
    function processMouseMove (event) { 
      // get IE event
      if (! event) {event = window.event;} 
      // turn cell blue if Ctrl key is pressed
      if (event.ctrlKey) {this.style.backgroundColor = "blue";} 
      // turn cell red if Shiftkey is pressed
      if (event.shiftKey) {this.style.backgroundColor = "red";}
      // turn cell white if Altkey is pressed
      if (event.altKey) {this.style.backgroundColor = "white";}
    }
    // -->
  </script> 
</head> <body onload = "createCanvas()"> 
  <table id ="canvas" class="canvas"><tbody id="tablebody">
      <tr><th class="key" colspan="1OO">Hold <tt>ctrl</tt>
          to draw blue. Hold <tt>shift</tt> to draw red. Hold <tt>alt</tt>to erase lines</th></tr>
  </tbody></table> 
</body> </html>

错误在'var side = 100;'

行上给出

1 个答案:

答案 0 :(得分:3)

你错过了{启动功能......

function createCanvas () {

相关问题