IE可以用setAttribute 的,你查看一下网页的源程序,看看cell是否添加了("onmouseover的属性!

解决方案 »

  1.   

    <html>
    <head>
    <script language="javascript">
    function addtablerow(address,price,comments) 
            {
            var rowIndex = document.getElementById("resultsbody").rows.length;
             var row = document.getElementById("resultsbody").insertRow(rowIndex);
               // var row=document.createElement("tr"); //建立一行 
                var cell=createRlement(address); //创建一个单元格节点 
                row.appendChild(cell);//把单元格节点增加到建立的行中 
                cell=createRlement(price); 
                row.appendChild(cell); 
                cell=createRlement(comments); 
                row.appendChild(cell); 
                //document.getElementById("resultsbody").appendChild(row); //把行增加到id为resultsbody 
                
            } 
            function createRlement(text) 
            { 
                var cell =document.createElement("td") //常见一个节点 
               // var tableNode=document.createTextNode(text); //创建一个文本节点 
                cell.innerText =  text;
                cell.setAttribute("onmouseover","alert('22')"); 
                alert(cell.outerHTML); //调试看看属性是否已经加进去了!
                return cell;//返回cell setAttribute
            } 
            function getdetail(text) 
            { 
                alert(text); 
            }  </script></head>
    <body>
    <table id="resultsbody" width="500px"><tr><td>22</td><td >33</td><td >44</td></tr></table>
     
    <input type="button" value="test" onclick="addtablerow('上海','100','很好')" /></body>
    </html>
      

  2.   

    cell.setAttribute("onmouseover","alert('22')"); 
                alert(cell.outerHTML); //调试看看属性是否已经加进去了! 
    setAttribute的第二个参数应该用引号引起来!
      

  3.   

    text 这个变量怎么传到getdetail()函数里啊?我看到的信息是"<td onmouseover="getdetail('text')"">sss</td>"
    应该是
    "<td onmouseover="getdetail("sss")"">sss</td>"
    这样才对的啊
    我改了一下
    cell.setAttribute("onmouseover","getdetail("text")"); 这样写不对
    cell.setAttribute("onmouseover","getdetail(text)");这样写的话得到的是
    "<td onmouseover="getdetail(text)"">sss</td>"
    怎么回事呢?
      

  4.   

    我把鼠标放到TD上怎么没有反应呢?onmouseover这个事件应该没有错啊
    怎么回事呢?
      

  5.   

    我看了一下浏览器返回的源代码,点击事件形成的行并没有被返回,而只是,原来的样子,如下所示,
                      <table id="resultsbody" width="500px">
    <tr>
    <td>22</td>
    <td>33</td>
    <td>44</td>
    </tr>
    </table>
    <input type="button" value="test" onclick="addtablerow('上海','100','很好')" />
    等待高手解释……
      

  6.   

    行列是由特定的语句添加的,参照如下:
    function addtablerow(address,price,comments) 
            { 
                var row=document.getElementById("resultsbody").insertRow(); //建立一行 
                var cell=row.insertCell(); //创建一个单元格节点 
                cell.innerText = address;
    cell.setAttribute("onmouseover",function(){getdetail(address)});
    // 或cell.onmouseover = function(){getdetail(address)};
    var cell=row.insertCell(); //创建一个单元格节点 
                cell.innerText = price;
    cell.setAttribute("onmouseover",function(){getdetail(price)});
    var cell=row.insertCell(); //创建一个单元格节点 
                cell.innerText = comments;
    cell.setAttribute("onmouseover",function(){getdetail(comments)});
            }

            function getdetail(text) 
            { 
                alert(text); 
            }
      

  7.   

    onmouseover这个属性是一个函数,你的getdetail函数没有返回值
    function getdetail(text) 
            { 
             return function (){
                 alert(text); 
                }
            }
      

  8.   

    明白了,呵呵,是我的alert()没有删除,呵呵