2011-04-09 87 views
0

我正在爲我的課程(javascript)編寫一個程序,它只是在畫布上繪製線條。並使用Alt鍵畫白,並給出它被「擦掉」的外觀。我完成了代碼,但我得到一個語法錯誤,不能看到我做錯了什麼。你們能幫忙嗎?繪圖腳本(JavaScript)的語法錯誤

<?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'行上'

回答

3

你缺少{啓動功能...

function createCanvas() {

+0

*在我搖頭* – 2011-04-09 02:51:18