<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script type="text/javascript">
        function initEvent() {
            var tableRating=document.getElementById("tableRating");
            var tds=tableRating.getElementsByTagName("td");
            for(var i=0;i<=tds;i++)
            {
            var td= tds[i];
            td.onclick=TdOnclick;
            td.style.cursor="pointer";
            }
        }
       
        function TdOnclick() {
            this.style.background:"red";
        }
    </script>
</head>
<body onload="initEvent() ">
<table id="tableRating">
<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr>
</table>
</body>
</html>
为什么总是提醒错误:Microsoft JScript 运行时错误: 属性“demo”的值为 null、未定义或不是 Function 对象

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
      <title></title>
      <script type="text/javascript">
      function initEvent() {
      var tableRating=document.getElementById("tableRating");
      var tds=tableRating.getElementsByTagName("td");
      for(var i=0;i<tds.length;i++)
      {
      var td= tds[i];
      td.onclick=TdOnclick;
      td.style.cursor="pointer";
      }
      }
        
      function TdOnclick() {
      this.style.background="red";
      }
      </script>
    </head>
    <body onload="initEvent() ">
    <table id="tableRating">
    <tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr>
    </table>
    </body>
    </html>
      

  2.   

    两处地方错了for(var i=0;i<tds.length;i++)
    this.style.background="red";
      

  3.   

    楼主发错代码了?你的代码中根本就没有demo变量,怎么会有关于demo的错误信息。