按下按钮后更改焦点
我有一个简单的按钮,它调用例程 onClick。 我用来
document.getElementById('Start').disabled=true;
禁用该按钮,这样就无法再次按下它。之后大多数事情都没有问题。在一种情况下,我需要检测按键按下,或者更确切地说,单击按钮后按键释放。我用来
document.onkeyup=WichKeyPressed;
检测按键按下。如果我不禁用该按钮,则效果很好,但如果禁用该按钮,则不起作用。
应该是对焦问题。如果我在屏幕上的空白区域上单击鼠标,无论是否禁用按钮都会检测到按键按下。我尝试过将焦点转移到其他几个元素,但到目前为止还没有成功。我什至给了 BODY 一个 id 并尝试将焦点转移到它,但结果保持不变。
我将不胜感激有关该主题的任何想法。 谢谢。
I have a simple button that calls a routine onClick.
I use
document.getElementById('Start').disabled=true;
to disable the button so it can not be pressed again. On most things there is no problem after that. In one instance I need to detect key presses, or rather key releases once the button is klicked.I use
document.onkeyup=WichKeyPressed;
to detect the key press. This works fine if I do not disable the button, but it does not work if I disable the button.
It must be a focus problem. If I click the mouse on a blank area on the screen, the key press is detected with or without disabling the button. I have tried changing the focus to several other elements, but so far no go. I have even given the BODY an id and tried to change focus to it, but the results remain the same.
I would appreciate any ideas on the subject.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加一个 CSS 类并设置一个标志,以防止单击按钮时再次发生该操作,而不是禁用该按钮。
Instead of disabling the button, you could just add a CSS class and set a flag preventing the action from happening again when the button is clicked.