jQueryのするevent.stopPropagation()メソッド
例
親要素にバブリングからクリックイベントを防ぎます:
$("span").click(function(event){
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
$("div").click(function(){
alert("The div element was clicked.");
});
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
$("div").click(function(){
alert("The div element was clicked.");
});
»をお試しください
定義と使用法
するevent.stopPropagation()メソッドは、親要素にバブリングする親イベント・ハンドラが実行される防止からのイベントを防ぎます。
ヒント:使用event.isPropagationStopped()このメソッドは指定されたイベントで呼び出されているかどうかを確認する方法。
文法
event.stopPropagation()
参数 | 描述 |
---|---|
event | 必需。 event 参数来自事件绑定函数。 |