Oct 31 2007

Firefox下提示“Node cannot be inserted at the specified point in the hierarchy”的问题

Posted by neio

Tags: , , ,

Node cannot be inserted at the specified point in the hierarchy” code: “3

出现这个问题是因为要被插入的元素不可插入。

在Firefox下,即使一个换行符号”\n”,都会被解析成DOM的一部分,使之成为一个文本域。而这个文本是不允许插入子节点的。而在IE下,就会忽略这些无意义的换行符等。

顺带提一下,我们通常都说Firefox更接近W3C标准,可偏偏在有些问题上,IE做的比Firefox好。Firefox对规范过于宽松的解释,很容易造成不必要的麻烦和错误,很多时候比不支持规范有过之无不及。

再举个例子:

<div name=”e1″>

<ul name=”e2″>

<li>op1</li>

<li name=”e3″></li>

</ul>

</div>

<a href=”#” name=”e4″>AA</a>

<form name=”e5″>

<input name=”e6″ type=”text”/>

</form>

使用一下Javascript来取值:

l = " ";

for(var i =1;i<7 ;i++){

l += document.getElementsByName("e"+i)[0].tagName + "  ";

}

alert(l);

那么在Firefox下将得到

div ul li a form input

而在IE下得到

a form input

因为DIV,UL,LI,P标记都不支持name属性,所以这里IE的做法是正确的。

Visits : 584 visited
Rating :
Bad oneNot good EnoughJust so soI like itPerfect !!! (2 votes, average: 2.5 out of 5)
Loading ... Loading ...
Filed under : Essay Pro, 汉语 |

Leave a Reply