jQuery停止“点击";第一次事件后的行动 [英] jQuery stop "click" action after first elevent
本文介绍了jQuery停止“点击";第一次事件后的行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个嵌套元素,每个元素都有不同的click
操作.
单击内部元素时,我需要停止外部元素的动作.
There are two nested elements, both have different click
actions.
I need to stop outer element action when inner element is clicked.
HTML:
<div id='out'>
<div id='in'></div>
</div>
jQuery:
$('#out').click(function(){alert('OUT div is pressed')})
$('#in').click(function(){alert('IN div is pressed')})
我需要在按下in
时执行,只有他的动作被执行. out
的脚本不应执行任何操作.
I need when in
is pressed, only his action is executed. out
's script should have no action.
如何解决?
推荐答案
您应使用 stopPropagation ():
$('#in').click(function(e){
alert('IN div is pressed')
e.stopPropagation();
});
这篇关于jQuery停止“点击";第一次事件后的行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文