msn上的tab功能Firefox对childNodes处理的一个BUG_Javascript教程-查字典教程网
msn上的tab功能Firefox对childNodes处理的一个BUG
msn上的tab功能Firefox对childNodes处理的一个BUG
发布时间:2016-12-30 来源:查字典编辑
摘要:Firefox对childNodes处理的一个BUGchildNodesFirefox在处理childNodes没有过滤换行与空格。所以在初...

Firefox对childNodes处理的一个BUG

childNodesFirefox在处理childNodes没有过滤换行与空格。所以在初次使用的时候,得到效果不是预期的效果。

HTML

复制代码 代码如下:

<ulclass="tbtn"ID="menuList">

<liclass="curr"id="tabap3_btn_0"onclick="tabit(this)">理财大学B</li>

<liid="tabap3_btn_1"onclick="tabit(this)">名医讲堂</li>

<liid="tabap3_btn_2"onclick="tabit(this)">名医讲堂</li>

<liid="tabap3_btn_3"onclick="tabit(this)">名医讲堂</li>

<liclass="lst"id="tabap3_btn_4"onclick="tabit(this)">影坛热点</li>

</ul>

JS

复制代码 代码如下:

functiontabit(btn)

{

varidname=newString(btn.id);

vars=idname.indexOf("_");

vare=idname.lastIndexOf("_")+1;

vartabName=idname.substr(0,s);

varid=parseInt(idname.substr(e,1));

vartabNumber=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对象时需要先对其判断或去掉空格。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类