父项点击但不是子项上的触发事件 [英] Trigger event on parent click but not on children

查看:126
本文介绍了父项点击但不是子项上的触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个父div,绝对定位,然后一个子div,有一个更高的z-index和相对定位,有没有办法有点击事件寄存器,只有当父div被点击,但不是内部div?



相关jsFiddle



更新了文字输入示例

解决方案

  $(。parent)click(function e){
if(e.target == this){
$(this).hide();
}
});


$ b b

演示: http://jsfiddle.net/Bt5HA/4/ p>

If I have a parent div that is positioned absolutely and then a child div that has a higher z-index and is positioned relatively, is there a way to have a click event register only if the parent div is clicked, but not the inside div?

Relevant jsFiddle

Updated fiddle with text input example

解决方案

$(".parent").click(function(e) {
    if (e.target == this) {
        $(this).hide();
    }
});​

DEMO: http://jsfiddle.net/Bt5HA/4/

这篇关于父项点击但不是子项上的触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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