就是当前元素相对其他相同元素所在的位置,从0开始。
比如
<div>
<p class='p1'></p>
<p class='p2'></p>
<p class='p3'></p>
</div>
var index1 = $('p1')index();
var index2 = $('p2')index();
var index3 = $('p3')index();
得到的index1,index2,index3的索引值分别为0,1,2
$(function () {
$("dt")on("click", function () {
alert($(this)index("dt"));
});
});
//index索引从0开始
<script type="text/javascript">
$(function(){
$("input")change(function(){
var curVal = $(this)val();
var prevVal = $(this)parent()prev("td")find("input")eq(0)val();
var nextVal = $(this)parent()next("td")find("input")eq(0)val();
alert("上一个文本框值:"+prevVal+"\n下一个文本框值:"+nextVal);
});
});
</script>
<table class="table table-hover" id="test123">
<tr>
<th width="45">选择</th>
<th width="100">驾校名称</th>
<th width="100">合作驾校名称</th>
<th width="100">申请时间</th>
<th width="100">申请状态</th>
<th width="100"> *** 作</th>
</tr>
<tr>
<td><input type="checkbox" name="id" value="1" /></td>
<td>中大驾校</td>
<td>潇湘驾校</td>
<td>2016-04-15 14:40:20</td>
<td class="tablestate">未处理</td>
<td><a class="change button border-blue button-little update" href="#">修改申请状态</a></td>
</tr>
<tr>
<td><input type="checkbox" name="id" value="1" /></td>
<td>中大驾校</td>
<td>潇湘驾校</td>
<td>2016-04-15 14:40:20</td>
<td class="tablestate">未处理</td>
<td><a class="change button border-blue button-little update" href="#">修改申请状态</a></td>
</tr>
</table>
扩展资料:
遍历同胞:
siblings():被选中时找到自己的兄弟姐妹,写法有siblings(所有的兄弟姐妹)和siblings(“同级的兄弟姐妹”)。
next():被选中时找到自己的下级,写法有 nextAll(找到所有的下级)和next(“找到下一个元素”)和nextuntil("被选中的元素的范围内的元素")。
prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞元素向后遍历,而不是向前)。
first():返回被选中的第一元素 ,写法 $("div p")first()css("样式") 。
last():被选中的最后一个元素,写法 $("div p")last()css(”样式“) 。
eq():返回被选中元素中有索引的元素,索引号,是从0开始不是从1开始比如treq(0)id ==dataeq[i-1]id 或者 tr[0]id = data[i-1]id。
filter():删除真正意义上的过滤,写法 $("div ")filter("span")hide() 。
not():就是跟filter()相反的用法。
以上就是关于jquery的索引值是什么概念全部的内容,包括:jquery的索引值是什么概念、jquery获取index()元素序号的问题、jquery 获取表格中当前单元格 td的索引值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)