且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

FireFox对TABLE中各元素的firstChild属性的处理(续)

更新时间:2022-06-13 21:53:30

听说HTML 5.0已经有一段时间了,但是并不知道它到底做了什么改进,这两天就看了下Specification,发现了下面一段话:

The markup snippet at the top of this section would be turned into the following DOM tree:

  • DOCTYPE: html
  • html
    • head
      • #text : ⏎␣␣
      • title
        • #text : Sample page
      • #text : ⏎␣
    • #text : ⏎␣
    • body
      • #text : ⏎␣␣
      • h1
        • #text : Sample page
      • #text : ⏎␣␣
      • p
        • #text : This is a
        • a href ="demo.html "
          • #text : simple
        • #text : sample.
      • #text : ⏎␣␣
      • #comment : this is a comment
      • #text : ⏎␣⏎

才发现在两个节点中插入一个#text节点是HTML5.0的标准,并不是只针对Table的特殊情况。先BS一下自己孤陋寡闻,继续努力!

由于Firefox 3.5支持HTML5.0,就写了一个简单的程序进行测试,验证了一下:

<html> <head> <title>Test HTML5.0</title> </head> <body> <div id="div1"> <span>ddd</span> </div> <p>This is a test program for HTML5.0.</p> <input type="button" value="test" onClick="testP()"> <script language="javascript"><!-- function testP(){ alert(document.body.firstChild.nodeName);//#text alert(document.getElementById('div1').firstChild.nodeName); //#text } // --></script> </body> </html>