html onfocus 选项卡与页面加载
假设我有一个文本框的 onFocus 事件。当用户按预期进入该框时,该事件就会触发。但似乎当选择该框时会触发该事件,然后通过切换选项卡、打开然后关闭另一个应用程序等来覆盖然后打开窗口。有没有一种方法可以使事件仅通过以下方式触发使用 Tab 键(或鼠标单击)文本框,而不是覆盖然后揭开窗口?
Let's say I have an onFocus event for a text box. That event triggers when the user tabs into that box, as expected. But it also seems like the event triggers when the box is selected, and then the window is covered and then uncovered, by switching tabs, opening then closing another application, etc. Is there a way to make it so that the event triggers only by tabbing (or mouse-clicking) the text box, and NOT by covering then uncovering the window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
onClick
事件。这只会在单击时触发事件,而不是按 Tab 键。您还可以使用
onKeyDown
,它会在按下任何按键时触发,但也会在用户从文本框移开时触发。http://jsfiddle.net/kBzAu/2/
You can use an
onClick
event. This will only trigger the event on the click though, not tabbing.You could also use
onKeyDown
which would trigger on any key press, but would also trigger when the user tabbed away from the textbox.http://jsfiddle.net/kBzAu/2/
当离开页面时,您可以使用
window.document.onblur=function(){disable all onFocus};
并使用
window.document.onfocus=function(){enable all onFocus};
重新激活它们when one goes away from page, you may use
window.document.onblur=function(){disable all onFocus};
and re activate them with
window.document.onfocus=function(){enable all onFocus};