msn上的tab功能Firefox對childNodes處理的一個BUG_導覽功能表

來源:互聯網
上載者:User
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對象時需要先對其判斷或去掉空格。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.