停止传播到附加元素 [英] Stop propagation to appended element

查看:79
本文介绍了停止传播到附加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将< a> 标记附加到我的 div

  $('< a class =dz-jcrophref =http://www.google.com> google< / a>')。 appendTo( 'DZ-图像预览。'); 

我想停止传播< a> 标签..但是当我尝试只选择我不能的元素时。我使用以下代码来测试是否选择了我的元素:

  $(document).on('click', '.dz-jcrop',function(){
console.log('me');
});

它不会被记录,并且元素未被选中。如何停止传播到附加元素?

解决方案

看到这个例子: http://jsfiddle.net/kevalbhatt18/6sjzada9/



使用return false;

>



  $('< a class =dz- jcrophref =http://www.google.com> google< / a>')。appendTo('。dz-image-preview'); 
$(document).on('click','.dz-jcrop',function(event){
console.log('me');
return false;
});



什么是返回和停止传播之间不同
请参阅此链接: https://stackoverflow.com/a/30475572/4696809

I append <a> tag to my div :

$('<a class="dz-jcrop" href="http://www.google.com"  >google</a>').appendTo('.dz-image-preview');

I want to stop propagation for <a> tag .. but when I try just to select the element I can't. I use the following code to log to test if my element is selected :

$(document).on('click', '.dz-jcrop', function(){ 
    console.log('me');
}); 

It doesn't get logged and the element is not selected. How to stop propagation to appended element?

解决方案

see this example: http://jsfiddle.net/kevalbhatt18/6sjzada9/

Use return false;

$('<a class="dz-jcrop" href="http://www.google.com"  >google</a>').appendTo('.dz-image-preview');
$(document).on('click', '.dz-jcrop', function(event){
    console.log('me');
    return false;
});

what is different between return and stopPropagation See this link: https://stackoverflow.com/a/30475572/4696809

这篇关于停止传播到附加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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