本文共 1476 字,大约阅读时间需要 4 分钟。
Event.preventDefault:
可阻止时间执行其默认功能:例如: 阻止想submit这样子,本身带有功能的属性,使其本身功能失效! 另一种失效的方法是return false,效果同上! Event.stopPropagation: 允许事件的默认功能发生,但阻止事件传播click
Click1的对应的函数会执行,click2的对应的函数不会被执行
.capture与.selfclick
methods: { div1:function(){ console.log('div1'); }, div2:function(){ console.log('div2'); }, div3:function(){ console.log('div3'); }, div4:function(){ console.log('div4'); }, }
当点击click的时候,console.log顺序为:
Div4,div3,div2,div1;
添加:.self
click
结果为:div4,div1
click
结果为:div3,div2,div4,div1
click
结果为:div2,div4,div3
prevent 是拦截默认事件,passive是不拦截默认事件。
转载地址:http://orezi.baihongyu.com/