alert(document.getElementById("a").innerHTML)

解决方案 »

  1.   


    <html>
    <head>
    <title></title>
    <script>
    function getTd()
    {
    //1
    alert(document.getElementById('a').innerHTML); //2
    alert(document.getElementById('a').innerText);
    }
    </script></head>
    <body>
    <table>
    <Tr>
    <td id="a">zhongguo </td> 
    </tr>
    </table>
    <input type="button" onclick="getTd()" />
    </body>
    </html>
      

  2.   

    學習了樓上請教 innerHTMLinnerText 有何差異
      

  3.   

    innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器,因此,尽可能地去使用innerHTML,而少用innerText
      

  4.   

    <td id="a"><a href = "http://www.baidu.com">百度</a> </td> 用innerHTML 可以获得  <a href = "http://www.baidu.com">百度</a>
    用innerText 可以获得  百度
      

  5.   

    document.getElementById('a').innerHTML   ///包括HTML符号

    document.getElementById('a').innerText   ///只包括文本
      

  6.   

    如果<td></td>之间只有文本的话
    建议使用innerHTML
    这样可以和FireFox兼容
      

  7.   

    alert(document.getElementById("a").innerHTML)