jquery中的e.stopPropagation()是否适用于锚标记 [英] does e.stopPropagation() in jquery works on anchor tag

查看:202
本文介绍了jquery中的e.stopPropagation()是否适用于锚标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望阻止来自锚标记内的元素的eventpropogation我试图使用e.stopPropagation();它似乎不起作用是可能或我只是浪费时间请帮助我离开这里
javascript是:

i want prevent eventpropogation from element inside an anchor tag i m trying to use e.stopPropagation(); it doesn't seem to work is it possible or i m just wasting time please help me out of here javascript is:

$(document).ready(function(){
    $('.alink .p').click(function(e){
    alert("hi");
    e.stopPropagation();  
});

html是:

<div>
    <a href="http://google.com" class="alink" >Google links
          <p class="p">Another Links to prevent default</p>
    </a>
</div>

感谢宝贵的时间

推荐答案

event.stopPropagation()停止将事件传递给DOM结构中的处理程序,该元素最初触发了事件。但是,它不会阻止已经执行的操作已被触发。

event.stopPropagation() stops passing the event to handlers further away in DOM structure from the element, on which originally event was triggered. It does not, although, prevent action that has already been triggered.

你应该使用 event.preventDefault() 来阻止提及d高于默认操作。

You should use event.preventDefault() to stop mentioned above default action.

来源:

  • event.preventDefault()
  • event.stopPropagation()

这篇关于jquery中的e.stopPropagation()是否适用于锚标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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