开发者

Syntax Error on Drawing Script (JavaScript)

I'm writing a program for my class (javascript) that simply draws lines on a canvas. And uses the alt key to draw white and give the appearance of it being 'Erased'. I finished the code, but i'm getting a syntax error and can't see what i'm doing wrong. Can you guys please help?

<?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;开发者_如何学C
              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>

the error is given on the line 'var side = 100;'


You are missing the { to start the function...

function createCanvas () {

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜