为什么警报在js中不起作用并且索引返回-1?
HTML 代码:
<ul id="menu-controls">
<li>
<a target="_self" onclick="return displaySubMenu(0);" id="menu-controls-0" href="#" class="">
<span>
Home
</span>
</a>
</li>
<li>
<a target="_self" onclick="return displaySubMenu(1);" id="menu-controls-1" href="#" class="">
<span>
Oleg Test
</span>
</a>
</li>
<li>
<a target="_self" onclick="return displaySubMenu(2);" id="menu-controls-2" href="#" class="act">
<span>
Products
</span>
</a>
</li>
</ul>
jQuery代码:
function displaySubMenu(menuid) {
var myActive = jQuery("a.act").parent().index();
var myClicked = jQuery("#menu-controls-"+menuid).parent().index();
alert(myActive+"==="+myClicked);
if (myActive < myClicked) {
alert("Previous active was left");
} else if (myActive > myClicked) {
alert("Previous active was right");
} else if (myActive == myClicked) {
alert("Previous active is this clicked one");
}
jQuery("a.act").removeClass("act");
jQuery("#menu-controls-"+menuid).addClass("act");
return false;
}