2021.11.10
作者:互联网
//基本事件
// $(".child").click(function(){
// console.log(0)
// })
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
event.preventDefault();
});
// $(".child").mousemove(function(e){ // console.log(e,offsetX,e.offsetY) // })
// $(".child").mouseover(function(){ // $(this).css("background-color","red"); // }).mouseout(function(){ // $(this).css("background-color","pink") //浮动效果 // }) function stopPropagation(e){ e.stopPropagation();//阻止事件冒泡 e.preventDefault();//阻止默认行为 reset submit a[href] return false;
}
$(".child").click(function(){ console.log(".child") return stopPropagation(e); })
$(".parent").click(function(){ console.log(".parent") }) })
jQuery event.stopPropagation() 方法
阻止 click 事件冒泡到父元素:
$("span").click(function(event){event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
jQuery event.preventDefault() 方法
防止链接打开 URL:
$("a").click(function(event){event.preventDefault();
});
标签:function,10,2021.11,event,click,child,console,stopPropagation 来源: https://www.cnblogs.com/chen-ao/p/15532684.html