這是我的javascript,它的效果很好,除非如果您單擊相同的鏈接兩次它切換。我如何避免這種情況發生?最終,我只是想顯示一個基於點擊項目的psection ...但是如果你點擊它兩次,它會切換。點擊兩次後鏈接切換
current = "intersitial"; // div with id="m0" is currently diplayed
function show_or_hide (id)
{
if (current) //if something is displayed
{
document.getElementById (current).style.display = "none";
if (current == id) //if <div> is already diplayed
{
current = 0;
}
else
{
document.getElementById (id).style.display = "block";
current = id;
}
}
else //if nothing is displayed
{
document.getElementById (id).style.display = "block";
current = id;
}
}
我的HTML是:
<ul>
<li onclick="show_or_hide('intersitial')"><span>intersitial</span></li>
<li onclick="show_or_hide('advancedDetail')"><span>advancedDetail</span></li>
<li onclick="show_or_hide('ultimateDetail')"><span>ultimateDetail</span></li>
</ul>
<div class="megamenu" id="intersitial">intersitial</div>
<div class="megamenu" id="advancedDetail" style="display: none">advancedDetail</div>
<div class="megamenu" id="ultimateDetail" style="display: none">ultimateDetail</div>
太棒了!非常感謝你做的這些!!!! –