当我在输入框上触发focus
事件时,它 会被调用,但在 UI 上,输入框没有聚焦。这种行为有什么原因吗?dispatchEvent
onfocus
var test = document.getElementById("test");
test.onfocus = function(event) {
console.log('focused');
}
var e = document.createEvent('Event');
e.initEvent("focus", true, true);
test.dispatchEvent(e);
另一方面,这按预期工作。
var test = document.getElementById("test");
test.focus();
我正在调查这个的原因是我使用 ZeptoJS 来触发事件并且它使用dispatchEvent
.