爲什麼點擊按鈕也會觸發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>
當我點擊該按鈕,這兩個事件火......爲什麼?
焦點上的按鈕。當你點擊它時,你也會激活它。也許你正在尋找'mouseenter'事件? –
只需單擊並等待,您將知道什麼是焦點,什麼是點擊 –
單擊某個對象也意味着您已將焦點轉移到該對象上。這個事件觸發是很自然的。 – Havenard