2016-03-31 62 views
0

enter image description here我想着重李標籤時,鏈接,在用戶點擊TABINDEX Dosent隱藏裏標籤內容

<li id="secondli"><a onclick="showscndbox();" id="secondlink" >How can I upload with my membership?</a></li>// tab to be clicked 


<div class="col-md-12 col-sm-12 col-xs-12" id="secondbox" style="display:none;" > 
    <div class="col-md-12 col-sm-12 col-xs-12 pro-box-in-faq" > 
    content to hide or show 
    </div> 
</div> 

有19個li標籤,我想使li標籤可聚焦的點擊次數和讓其他DIV隱藏

function showthrdbox() { 
    //ta 
    document.getElementById("thirdbox").style.display = "block"; 

    $("#thrdli").attr('tabindex',2).focus(); 

    document.getElementById("secondli").removeAttr('tabindex'); 
    document.getElementById("secondbox").style.display = "none"; 
} 

這個腳本集中點擊li標籤,但不會讓另一個div隱藏。請讓我知道解決方案。

+0

爲什麼要更改tabindex?它與元素的可見性無關。 –

+0

@GeraldSchneider當我添加tabindex屬性來集中它停止隱藏以前的li標籤的內容 –

回答

0

這是你想要的嗎?目標李會聚焦,其他李將被隱藏? 如果是這樣,請檢查以下代碼:

function showscndbox(e) { 
    var anchor = e.target; 
    var p = anchor.parentNode; 
    var pp = p.parentNode; 
    for (var i in pp.childNodes) { 
     var child = pp.childNodes[i]; 
     if (child != p) { 
      child.style.display = "none"; 
     } 
    } 
    p.style.display = ""; 
} 
+0

我建議你使用JQuery來處理這種編碼。這會容易很多。 – hoffman

+0

請檢查附件。我想要關注點擊li標籤上的li標籤,但是如果我打開另一個應該隱藏以前li標籤內容的li標籤。內容被dsiplayed在被點擊的li標籤的底部。 –