且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按下TAB或ENTER或BACK时未触发按键事件

更新时间:2023-12-03 08:05:16

这是因为这些键根本不会调用此事件;所有按键操作都不会调用事件 onkeypress ,但主要是在输入字符时(但也可以将Backspace视为代码点#8)。您可以使用事件 keydown keyup onblure (而不是Tab),在 onfocus (而不是Tab):

http://www.w3schools.com/tags/ref_eventattributes.asp [ ^ ],

http:// www.w3schools.com/tags/ev_onkeypress.asp [ ^ ]。



-SA
This is because these keys don't invoke this event at all; the event onkeypress is not invoked on all key presses, but mostly when a character is input (but also, say, Backspace considered as code point #8). You can use the events keydown, keyup, onblure (instead of Tab), on onfocus (instead of Tab):
http://www.w3schools.com/tags/ref_eventattributes.asp[^],
http://www.w3schools.com/tags/ev_onkeypress.asp[^].

—SA