用query通過類來選擇元素,但是index索引值卻不對,我希望的是按照順序012345這樣,可是sub-nav的li索引又是從0開始
html代碼
<ul class="nav nav-pills nav-stacked main-nav" role="tablist">
<li class="nav-bar">LAYOUT</li> <li class="nav-bar">SIGNAL</li> <li class="nav-bar">USER</li> <li id="sys">SYSTEM SETTING <ul class="sub-nav"> <li class="nav-bar">SYSTEM TIME</li> <li class="nav-bar">NET SETTING</li> <li class="nav-bar">VERISION INFO</li> <li data-toggle="modal" data-target="#quit">QUIT</li> </ul> </li> </ul>
js代碼
$(".nav-bar").click(function(){
var index=$(this).index(); console.log(index); });