我試圖創建一個自定義下拉,並使用下面的代碼工作得很好 - 只有一個問題是,如果我有多個下拉,所有鏈接只會激活第一個下拉。任何想法,我會如何解決這個問題? (是的,我知道口魚我只需要得到這個工作)自定義下拉
function toggle() {
var ele = document.getElementById("dropdown-items");
var text = document.getElementById("dropdown-menu");
if(ele.style.display == "block") {
ele.style.display = "none";
}
else {
ele.style.display = "block";
}
}
HTML如下:
<div id="mainSearch">
<div id="search-cat">
<div class="search-title">Destination</div>
<div id="cat-dropdown">
<a id="dropdown-menu" href="javascript:toggle();">Choose a Category...</a>
<div id="dropdown-items">
<ul>
<li id="dropdown-list"><a href="">Category One</a></li>
<li id="dropdown-list"><a href="">Category Two</a></li>
<li id="dropdown-list"><a href="">Category Three</a></li>
</ul>
</div>
</div>
</div>
<div id="search-cat">
<div class="search-title">Location</div>
<div id="cat-dropdown">
<a id="dropdown-menu" href="javascript:toggle();">Choose a Location...</a>
<div id="dropdown-items">
<ul>
<li id="dropdown-list"><a href="">Category One</a></li>
<li id="dropdown-list"><a href="">Category Two</a></li>
<li id="dropdown-list"><a href="">Category Three</a></li>
</ul>
</div>
</div>
</div>
</div>
什麼是HTML? – 2010-03-22 13:30:39