JQuery反转表选择
我有这样的页面部分JQuery反转表选择,jquery,jquery-selectors,Jquery,Jquery Selectors,我有这样的页面部分 <div id="inbox"> <h1>Headline</h1> <p>First paragraph</p> <table> <tbody> <tr> <td>table stuff</td> </tr> </tbody> </table>
<div id="inbox">
<h1>Headline</h1>
<p>First paragraph</p>
<table>
<tbody>
<tr>
<td>table stuff</td>
</tr>
</tbody>
</table>
<p>Second paragraph</p>
</div>
但这不起作用,因此如何反转“收件箱”中表格的选择?试试
$('#inbox table').siblings().click(function(){
alert('hello inbox');
});
或
由于单击处理程序出现气泡,您可以执行以下操作: 1.只有孩子,而不是桌子:
$("#inbox > *:not(:table)").click(function(e){ ... });
// or
$("#inbox").children(':not(table)').click(function(e){ ... }):
2.单个事件:
$("#inbox").click(function(e){
// Not a descendant of table or this div
if( $(e.target).closest('table').length === 0 && e.target !== this ){
// Do something
}
});
因此,我的选择器是:“收件箱中的所有内容,但不是表或任何表的后代:
$('#inbox *:not(table,table *)').bind('click', function(){
alert($(this).text())
});
$("#inbox").click(function(e){
// Not a descendant of table or this div
if( $(e.target).closest('table').length === 0 && e.target !== this ){
// Do something
}
});
$('#inbox *:not(table,table *)').bind('click', function(){
alert($(this).text())
});