jquery中的e.stopPropagation()是否适用于锚标记 [英] does e.stopPropagation() in jquery works on anchor tag
问题描述
我希望阻止来自锚标记内的元素的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()
- event.preventDefault()
- event.stopPropagation()
这篇关于jquery中的e.stopPropagation()是否适用于锚标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!