jQuery Click Event On Div, Except Child Div(Div 上的 jQuery Click 事件,子 Div 除外)
问题描述
我有以下 HTML:
<div class="server" id="32">
<a>Server Name</a>
<div class="delete-server">X</div>
</div>
我正在尝试这样做,因此当用户单击 server
div 时,它会弹出一个编辑对话框.问题只是在做:
I am trying to make it so when users click the server
div it brings up an edit dialog. The problem is simply doing:
$(".server").click(function () {
//Show edit dialog
});
不起作用,因为如果他们单击删除的 X,它会弹出编辑对话框.怎样才能让整个div server
除了delete-server
div 之外都有点击事件.
Does not work, because if they click the X which is delete, it brings up the edit dialog. How can make the entire div server
have the click event except the delete-server
div.
推荐答案
$(".server").on('click', ':not(.delete-server)', function (e) {
e.stopPropagation()
// Show edit dialog
});
这是小提琴:http://jsfiddle.net/9bzmz/3/
这篇关于Div 上的 jQuery Click 事件,子 Div 除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!