相关疑难解决方法(0)

jquery Event.stopPropagation()似乎不起作用

我完全不知道应该做什么吗?我希望如果我在一个事件上调用stopPropagation(),那么该事件的处理程序将不会在祖先元素上触发,但下面的示例不是那样工作的(至少在FireFox 3中).

<script type="text/javascript">
    $("input").live("click", function(event){
        console.log("input click handler called")
        event.stopPropagation()
    });

    $("body").live("click", function(event){
        console.log("body was click handler called. event.isPropagationStopped() returns: " + event.isPropagationStopped());
    })

</script>

 ...

<body>
    <input type="text" >
</body>
Run Code Online (Sandbox Code Playgroud)

jquery events

22
推荐指数
1
解决办法
2万
查看次数

阻止点击儿童解雇父点击事件

我有一个选择器绑定一个将删除弹出窗口的单击事件.但是,我只希望选择器处理单击,而不是选择器的子节点才能触发单击事件.

我的代码:

<div id="popup">
  <div class="popup-content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum …
Run Code Online (Sandbox Code Playgroud)

jquery click

12
推荐指数
2
解决办法
2万
查看次数

单击除链接之外的div的Fire事件

我想在点击div时触发一个事件,但如果我点击该div上的特定链接,我不希望触发该事件:

我的JS

$("#myDiv").not("#myLink").click(function () {
    alert("clicked");
});

//Or

$("#myDiv:not(#myLink)".click(function () {
    alert("clicked");
});

$("body").on('click', '#myLink', function(e) {
    e.stopPropagation();
});
Run Code Online (Sandbox Code Playgroud)

我的HTML

<div id="myDiv">
    <a href="#" id="myLink">Some link</a>
</div>
Run Code Online (Sandbox Code Playgroud)

这是jsfiddle

编辑:其实我的真实代码是" "方法,我已经尝试过stopPropagation但是在那种情况下不起作用

jquery

6
推荐指数
1
解决办法
1638
查看次数

使用 jQuery 单击外部容器时隐藏 div

我有 2 个 div,一个重叠在另一个上面。当我单击外部 div 时,我想隐藏内部 div。当我点击内部 div 时,内部 Div 不会发生任何事情。同时,内部 div 中的链接应该可以正常工作。如何使用 jquery 做到这一点?

<div class="outer">
    <div class="inner"></div>
</div>

.outer {
    background-color: #000;  
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9998;
    height: 100%;
    width: 100%;
    opacity: 0.5;
}

.inner {
    background-color: blue;
    width: 240px;
    position: fixed;
    z-index: 9999;
    left: 50%;
    top: 50%;
    margin-left: -300px;
    margin-top: -150px;
}
Run Code Online (Sandbox Code Playgroud)

无法按预期工作的 jQuery 代码:

$('.outer').click(function(e){
    $('.inner').hide();
});

$('.inner').click(function(e){
    return false;
});   
Run Code Online (Sandbox Code Playgroud)

jquery

2
推荐指数
1
解决办法
3278
查看次数

标签 统计

jquery ×4

click ×1

events ×1