js获取标签下标
<body> <div class="titTab"> <span>低</span> <span>中</span> <span class="select">高</span> </div>
<input type="button" value="获取下标" class="target"/>
</body>
$(".target").click(function(){ //方法一 注意空格与非空格 var index = $('.titTab span.select').index(); //方法二 //var index = $('.titTab .select').index(); alert("index:"+index);//弹出index:2
});
//选择低中高 $('.titTab span').click(function() { var i = $(this).index();//下标从0开始 0,1,2 $(this).addClass('select').siblings().removeClass('select'); });
if you want to go fast,go alone,if you want to go far,go together