分别alert innerHTML看看是啥

解决方案 »

  1.   

    var table = document.getElementById("table1");
    var tds = table.getElementsByTagName("td");
    --------------------------
    先了解table的结构,
    你的table 应该像下面那样写
    <table>
    <tbody>
    <tr>
    <td>td1</td>
    </tr>
    </tbody>
    </table>
    然后table 先找到tbody再找到tr才能找到td
      

  2.   

    <script language="javascript">
    function init()
    {
    var table = document.getElementById("table1");
    var tds = table.getElementsByTagName("td");
    for(var i = 0 ; i < tds.length ;i++)
    {
    note = tds[i].children;
    //alert(tds[i].children.length);

    tds[i].onclick = function()
    {
    if(this.children[0].id.indexOf("userName") != -1)
    {
    this.children[0].style.display = "none";
    this.children[1].style.display = "";
    }
    }

    tds[i].children[1].onblur = function()
    {
    this.parentElement.children[0].style.display = "";
    this.parentElement.children[1].style.display = "none";
    this.parentElement.children[0].innerText = this.parentElement.children[1].value;
    }
    }
    }
    window.onload = init;
    </script>