one:
- one
- two
- three
这段代码在火狐下输出为‘undefined’,在IE下输出为‘item2’。请看two代码。
two:
- one
- two
- three
IE下输出1、3;火狐下输出3、7。(节点类型为1表示元素节点,节点类型为3表示文本节点)
总结1与2:在火狐下空白、换行等文本信息也会被当成nextSibling跟childNodes的一员或作用对象!
解决方案:
1、去掉空白和换行。这样做绑定了HTML的结构,让程序和HTML产生了耦合!
2、见代码three.
three:
- one
- two
- three
有没有好的方法?见代码four。
four:
- one
- two
- three
通过
five:
- one
- two
- three
可读性这么差的代码。。。不用看了,看代码SIX。-封装成getNextNode。
six:
- one
- two
- three