网站开发待遇,网站建设首期款,建立网站的软件,wordpress防止镜像2019独角兽企业重金招聘Python工程师标准 根据《jquery基础教程》 第一种方法#xff1a;判断事件的“直接”目标是否是自身#xff0c;如果不是自身#xff0c;不予处理 $(div.outter).click(function(event) {if (event.target this) {$(p).css(color, red… 2019独角兽企业重金招聘Python工程师标准 根据《jquery基础教程》 第一种方法判断事件的“直接”目标是否是自身如果不是自身不予处理 $(div.outter).click(function(event) {if (event.target this) {$(p).css(color, red);}
}); //该div事件handler忽略了冒泡内部元素的点击事件不会联带外部产生副作用第二种方法在直接目标中终止事件传递 $(h3).click(function(event){console.log(Enter h3 click event handler);event.stopPropagation(); // 终止了事件的冒泡传递
}); 第三种方法由于stopPropagation并不能阻止“默认行为”如果想要阻止默认行为那么使用 event.preventDefault()所谓的默认行为例如点击a会打开一个新的网页链接惦记submit会提交一个表单。默认行为的触发并不在普通的事件流当中。 $(a).click(function(event){event.preventDefault();// do something
}); 转载于:https://my.oschina.net/u/566896/blog/830281