
consolelog(datas[i]attr('data-index'))
改为
consolelog($(datas[i])attr('data-index'))
或
consolelog(datas[i]getAttribute('data-index'))
或
consolelog(datas[i]datasetindex)
或
consolelog($(datas[i])data('index'))
建议使用最后一种
首先,你的checkbox的id本身就带有索引("_"后面的东东),处理字符串可以得到
你想用index()的方法的话你只能先找到那个checkbox的父元素td,td在的index()的值即为checkbox的索引
$("CheckBoxList1_0")parent()index()
可以用jQ的index()方法,举例:
<table id="table1"><tr>
<td>第1行</td>
</tr>
<tr>
<td>第2行</td>
</tr>
<tr>
<td>第3行</td>
</tr>
<tr>
<td>第4行</td>
</tr>
</table>$('#table1')find('tr')click(function() {
var idx = $(this)index() + 1; // 索引是从0开始的,故+1
consolelog('点击了第' + idx + '行');
});
attr(name|properties|key,value|fn)
参数
nameStringV10
属性名称
properties MapV10
作为属性的“名/值对”对象
key,value
String,ObjectV10
属性名称,属性值
key,function(index, attr)
String,FunctionV11
1:属性名称。
2:返回属性值的函数,第一个参数为当前元素的索引值,第二个参数为原先的属性值。
参数name 描述:
返回文档中所有图像的src属性值。
jQuery 代码:
$("img")attr("src");
以上就是关于jquery 获取所有元素的data-index全部的内容,包括:jquery 获取所有元素的data-index、jquery 获取Checkbox索引。。。。。。。。。。。。。、jquery如何获取取元素序号,例如一个有N行的table,点击其中的一行,获取到它的行号。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)