为什么单击按钮也会触发 focus
事件?
如果我有这个
$('button').on('click', function(e){
console.log('This was a ' + e.type);
});
$('button').on('focus', function(e){
console.log('This was a ' + e.type);
});
和 HTML
<button>Click me</button>
当我单击按钮时,两个事件都会触发...为什么?
最佳答案
因为 <button>
始终触发焦点事件(当您单击它时)。正如您可以在 http://api.jquery.com/focus/ 中阅读的那样
"The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (
<input>
,<select>
, etc.) and links (<a href>
)."
关于javascript - 为什么单击按钮会触发焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23707478/