【发布时间】:2011-07-01 13:42:15
【问题描述】:
我目前正在编写一个手风琴,遇到了与nextSibling difference between IE and FF? 中描述的相同的问题 - 特别是 Microsoft 的 nextSibling / nextElementSibling 与其他人实现的区别。
由于各种原因,使用 jquery 不是一种选择。也不是让我所有的 MS 用户都升级到 MSIE9
目前我正在使用以下代码来解决该问题:
// tr is a TR doc element at entry....
while (nthRow--) {
// for Chrome, FF tr=tr.nextElementSibling; for MSIE...tr=tr.nextSibling;
tr=tr.nextElementSibling ? tr.nextElementSibling : tr=tr.nextSibling;
if (!tr || tr.nodeName != "TR") {
break;
}
tr.style.display="";
}
这似乎符合我在 MSIE6、FF 和 Chrome 中的预期 - 即初始 TR 下方的 nthRow TR 元素可见(以前为 style.display="none")。
但这可能会产生意想不到的副作用吗?
(我是 Javascript 的新手;)
【问题讨论】: