当前位置: 首页 > 图文教程 > 网络编程 > Javascript > msn上的tab功能Firefox对childNodes处理的一个BUG

Javascript
window.onload 加载完毕的问题及解决方案(下)
jQuery 版本的文本输入框检查器Input Check
jquery Firefox3.5中操作select的问题
jquery 1.3.2 IE8中的一点点的小问题解决方法
javascript div 遮罩层封锁整个页面
javascript 页面只自动刷新一次
Javascript 区别浏览器 代码
checkbox 复选框不能为空
Prototype 学习 Prototype对象
Prototype 学习 工具函数学习($方法)
Prototype 学习 工具函数学习($A方法)
Prototype 学习 工具函数学习($w,$F方法)
Prototype Object对象 学习
Prototype Function对象 学习
Prototype Date对象 学习
JavaScript 事件对象的实现
JavaScript 事件查询综合
JavaScript 继承详解(一)
JavaScript 继承详解(二)
JavaScript 继承详解(三)

Javascript 中的 msn上的tab功能Firefox对childNodes处理的一个BUG


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 448 ::
收藏到网摘: n/a

今天公司用到一个tab功能发现 msn上的不错,但是在firefox兼容不好,msn他们的方法就是用了不少的div包含,不过网上有高人解决了。 Firefox对childNodes处理的一个BUG
childNodesFirefox在处理childNodes没有过滤换行与空格。所以在初次使用的时候,得到效果不是预期的效果。
HTML
复制代码 代码如下:

<ul class="tbtn" ID="menuList">
<li class="curr" id="tabap3_btn_0" onclick="tabit(this)">理财大学B</li>
<li id="tabap3_btn_1" onclick="tabit(this)">名医讲堂</li>
<li id="tabap3_btn_2" onclick="tabit(this)">名医讲堂</li>
<li id="tabap3_btn_3" onclick="tabit(this)">名医讲堂</li>
<li class="lst" id="tabap3_btn_4" onclick="tabit(this)">影坛热点</li>
</ul>

JS
复制代码 代码如下:

function tabit(btn)
{
var idname = new String(btn.id);
var s = idname.indexOf("_");
var e = idname.lastIndexOf("_")+1;
var tabName = idname.substr(0, s);
var id = parseInt(idname.substr(e, 1));
var tabNumber = btn.parentNode.childNodes.length; //IE和FF的值不同
for(i=0;i<tabNumber;i++)
{
if(document.getElementById(tabName+"_div_"+i)!=null) //这里需要进行判断
{
document.getElementById(tabName+"_div_"+i).style.display = "none";
document.getElementById(tabName+"_btn_"+i).style.backgroundImage = "url(pic/t-1-2.gif)";
document.getElementById(tabName+"_btn_"+i).style.borderBottomColor = "#D7F2DA";
document.getElementById(tabName+"_btn_"+i).style.cursor = "pointer";
}
}
document.getElementById(tabName+"_div_"+id).style.display = "block";
btn.style.backgroundColor = "#fff";
btn.style.borderBottomColor = "#fff";
btn.style.cursor = "default";
}

在IE上menuList的childNodes.length的值为5,而在Firefox值为11.因此我们在使用childNodes对象时需要先对其判断或去掉空格。