Javascript jquery/jqueryui,单击div按钮中的任意位置
我有一个div作为ui小部件内容,而h3作为ui小部件头。标题有三个按钮。每个类分别有“保存”、“删除”和“取消”类。我想在您单击div时使用.click功能,除非您实际单击其中一个按钮 我试过:Javascript jquery/jqueryui,单击div按钮中的任意位置,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我有一个div作为ui小部件内容,而h3作为ui小部件头。标题有三个按钮。每个类分别有“保存”、“删除”和“取消”类。我想在您单击div时使用.click功能,除非您实际单击其中一个按钮 我试过:$(.record”)。不(“.save”)。不(“.delete”)。不(“.cancel”)。单击( 我的代码是: <div class="record cursorPointer hoverClass ui-widget-content"> <h3 class="ui-wi
$(.record”)。不(“.save”)。不(“.delete”)。不(“.cancel”)。单击(
我的代码是:
<div class="record cursorPointer hoverClass ui-widget-content">
<h3 class="ui-widget-header">
<table width="100%"><tr>
<td align="left" style="width:33%; color:Red">somecontractorone</td>
<td style="width:33%" align="center"> Name: Joe Q Shmoe </td>
<td style="width:33%" align="right"> Buisness: joeqshmoeelectrical</td>
<td><button style="width:20px;height:20px" class="save"></button></td>
<td><button style="width:20px;height:20px" class="delete"></button></td>
<td><button style="width:20px;height:20px" class="cancel"></button></td></tr>
</table>
</h3>
</div>
萨莫科隆
姓名:Joe Q Shmoe
业务:Joeqshmoeelectric
但是,单击按钮时,单击功能仍处于激活状态
有什么想法吗?您可以使用
事件.target
查看单击的内容。然后依靠冒泡,将单击处理程序附加到父div
上
假设您有另一个(或多个)事件处理程序来处理按钮,您可以使用
$('button').click(function(e) {
e.stopPropagation();
switch( this.className ) {
// Or whatever...
}
})
在按钮的单击处理程序中使用
e.stopPropagation()
:
下面是一个演示:
和一些关于
e.stopPropagation()
:'$(“.record”)。单击(函数(e){if(!$(e.target).is(':button')){行得通。但我不确定它是否行得通,我的方式也不行…@kralco626-如果你仍然有问题,试试JSFIDLE的例子。我用e.target获得了它。只是不确定它为什么不能用我的方式工作,但没关系。谢谢!很好的解决方案,正是我需要的。谢谢!很高兴帮助@IgorAugustoIm很可能会使用Josiah的so直到我真正去实现按钮点击,这是一个好主意。
$('button').click(function(e) {
e.stopPropagation();
switch( this.className ) {
// Or whatever...
}
})
$('button').click(function(e) {
e.stopPropagation();
alert('you clicked a button!');
});