我想noclick从click函数中排除该类:
$( ".click" ).on( "click", ":not(.noclick *)", function() {
console.log( $( this ).text() );
});Run Code Online (Sandbox Code Playgroud)
.noclick{
background-color:pink;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="width:100%">
<tr class="click">
<th>Click</th>
<th>Click</th>
<th class="noclick">Nothing should happen here</th>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
只需从中删除星号即可 ":not(.noclick *)"
这使得它.noclick的后代上的事件不会触发该函数,但不会阻止.noclick自身.
$( ".click" ).on( "click", ":not(.noclick)", function() {
console.log( $( this ).text() );
});Run Code Online (Sandbox Code Playgroud)
.noclick{
background-color:pink;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="width:100%">
<tr class="click">
<th>Click</th>
<th>Click</th>
<th class="noclick">Nothing should happen here</th>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |