用query通过类来选择元素,但是index索引值却不对,我希望的是按照顺序012345这样,可是sub-nav的li索引又是从0开始
html代码
LAYOUT
SIGNAL
USER
SYSTEM SETTING
- QUIT
js代码
$(".nav-bar").click(function(){
var index=$(this).index();
console.log(index);
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
index() 方法返回指定元素相对于其他指定元素(同级)的 index 位置
这段代码试试
谢邀
如果特别复杂的话,用.each()遍历。然后你想怎么做都可以。