A bug in Firefox's childNodes Processing
ChildNodesFirefox does not filter line breaks and spaces when processing childNodes. Therefore, the first time you use it, the expected results are not.
HTML
Copy codeThe Code is as follows:
<Ul class = "tbtn" ID = "menuList">
<Li class = "curr" id = "tabap3_btn_0" onclick = "tabit (this)"> Finance University B </li>
<Li id = "tabap3_btn_1" onclick = "tabit (this)"> medical lecture hall </li>
<Li id = "tabap3_btn_2" onclick = "tabit (this)"> medical lecture hall </li>
<Li id = "tabap3_btn_3" onclick = "tabit (this)"> medical lecture hall </li>
<Li class = "lst" id = "tabap3_btn_4" onclick = "tabit (this)"> film hotspot </li>
</Ul>
JS
Copy codeThe Code is as follows:
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; // The values of IE and FF are different.
For (I = 0; I <tabNumber; I ++)
{
If (document. getElementById (tabName + "_ div _" + I )! = Null) // you need to determine
{
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 ";
}
On IE, the value of childNodes. length of menuList is 5, and the value of Firefox is 11. Therefore, when using the childNodes object, we need to judge it first or remove spaces.