请问哪个先执行呢?如果是事件默认行为先执行,那为什么可以使用preventDefault(),returnValue=false等方式阻止默认行为呢?
1
Septembers 2015-07-06 22:54:31 +08:00
|
2
lyhper OP @Septembers 谢谢你,事件冒泡我知道,但是和这个好像没关系呀?比如点击一个checkbox,是先勾选它还是先执行事件处理程序?
|
3
FuryBean 2015-07-06 23:33:47 +08:00 1
先上规范:
https://w3c.github.io/uievents/#event-flow-default-cancel 大部分情况下EventListener先执行,规范上有写: Default actions should be performed after the event dispatch has been completed, but in exceptional cases may also be performed immediately before the event is dispatched. 接着举了一个例子,就是checkbox的例子: The default action associated with the click event on <input type="checkbox"> elements toggles the checked IDL attribute value of that element. If the click event's default action is cancelled, then the value is restored to its former state. |