Javascript 如何使用jquery查找哪个子级具有表的特定类?

Javascript 如何使用jquery查找哪个子级具有表的特定类?,javascript,jquery,Javascript,Jquery,如何使用jquery查找具有“普通排序表”类的表的哪个子级具有“nosort”类?我想用'nosort'类提醒th的列号 <table class="normal-sort-table"> <thead> <tr> <th>#</th> <th>First Name</th> <th>Last Name&l

如何使用jquery查找具有“普通排序表”类的表的哪个子级具有“nosort”类?我想用'nosort'类提醒th的列号

<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>

#
名字
姓
用户名
1.
做记号
奥托
马克246
$(文档).ready(函数(){
if($('.normal sort table tr th').hasClass(“nosort”){alert('column number with nosort class alert here'))
})
您可以使用jq方法:


如果您想要精确列号,那么您必须写入

alert($('th.nosort').index()+1);
因为指数从零开始

alert($('th.nosort').index());
警报($('th.nosort').index()+1)

#
名字
姓
用户名
1.
做记号
奥托
马克246

您能解释一下您的答案吗?当然可以,但如果您将答案的相关部分添加到问题中,也会很有帮助。
alert($('th.nosort').index()+1);
alert($('th.nosort').index());