jQuery Click Div On Div,除了Child Div [英] jQuery Click Event On Div, Except Child Div

查看:67
本文介绍了jQuery Click Div On Div,除了Child Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML:

<div class="server" id="32">
  <a>Server Name</a>
  <div class="delete-server">X</div>
</div>

我试图在用户点击服务器 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 服务器具有除 delete-server div之外的click事件。

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/

这篇关于jQuery Click Div On Div,除了Child Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆