如何使用jquery查找哪个孩子具有表的特定类
How to find which th child has the particular class for a table using jquery?
如何使用jquery找到哪个孩子对带有"正常排序表"类的表具有"nosort"类?我想用"nosort"类提醒列号。
<table class="normal-sort-table">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th class="nosort">Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>mark246</td>
</tr>
</tbody>
</table>
<script>
$( document ).ready(function() {
if ( $('.normal-sort-table tr th').hasClass( "nosort" ) ) {alert( 'column-number-with-nosort-class-alert-here' )}
})
</script>
你可以使用 jq .index() 方法:
$('.normal-sort-table tr th.nosort').index()
alert($("th").index($(".nosort")));
如果你想精确列号,那么你已经写
alert($('th.nosort').index()+1);
因为索引从零开始。
alert($('th.nosort').index());
alert($('th.nosort').index()+1);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table class="normal-sort-table">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th class="nosort">Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>mark246</td>
</tr>
</tbody>
</table>
相关文章:
- jQuery:下拉;选项:第一个孩子“;作为选择器
- Jquery/Javascript—查找父级's的兄弟姐妹's儿童'的孩子
- 当我有一个独特的孩子 + jquery 时,如何获得最后一个孩子
- 在 JavaScript 中选择孩子,因为我不能使用 jQuery
- jQuery:第一个孩子(没有 id 或类)
- 如何使用jquery查找哪个孩子具有表的特定类
- jQuery代码:从父级到子级;不是从孩子到父母
- jQuery:查找前两个孩子
- Javascript到Jquery的转换,每次迭代都会删除第一个孩子
- Jquery的eq(0),“.first-child”,first()如果它是一个iframe,则不会抓住第一个孩子
- JQuery :has(),我需要只选择孩子
- Jquery”;对于“;循环查找有多少孩子
- 为什么这个jQuery脚本不会突出显示我列表中的第一个孩子
- jQuery's少选择,区别对待每个孩子
- jQuery:设置高度<部分>达到所有孩子的身高
- jQuery,很多孩子.有什么更好的方法来做这件事?
- jQuery帮助取消勾选父,我需要切换孩子复选框
- Jquery打开菜单onclick,停止他们和添加孩子
- jQuery -删除模糊元素,但捕捉点击他的孩子
- jquery toggleClass的孩子悬停