第89天 a标签的href和onclick属性同时存在时哪个先触发?
Activity
xxf1996 commentedon Jul 14, 2019
应该是
onclick
属性先触发,判断依据是在onclik
中使用preventDefault
方法可以阻止a
标签的跳转,说明a
标签的跳转行为是一个默认行为;如下:xjt31012 commentedon Jul 15, 2019
测试了一下,是
href
里的先触发haizhilin2013 commentedon Jul 15, 2019
@xjt31012 为什么呢?
huangsw0411 commentedon Jul 15, 2019
先执行onclick,最后载入到href的链接。
kruzabc commentedon Jan 8, 2020
onclick
事件先触发, 如果函数执行返回false
(全等), 则href
不会被触发。只在
chrome
和frrefox
中试过