Readonly输入字段不会在IE6中触发OnKeyPress

时间:2022-08-08 17:09:30

I am implementing a special behaviour for the Enter key. The problem is my ASP.net library generates a readonly field; and when users tab into this field (tabbing into it is meaningful; so I want that behaviour) and press Enter to submit the form, it won't submit because it's a readonly field.

我正在为Enter键实现一个特殊的行为。问题是我的ASP.net库生成了一个只读字段;当用户选中此字段时(对其进行选项卡有意义;所以我想要这种行为)并按Enter键提交表单,它不会提交,因为它是一个只读字段。

I wrote a workaround that hooks up your ordinary onkeypress=checkEnter, but IE6 will still not fire this event; Firefox will.

我写了一个解决方法,挂钩你的普通onkeypress = checkEnter,但IE6仍然不会触发此事件; Firefox会。

Whan can I do to detect an Enter on an IE6 readonly field?

我可以在IE6 readonly字段上检测Enter吗?

Thanks!

1 个解决方案

#1


For some reason IE6 won't detect pressing ENTER on the keypress event. It does however detect ENTER on the keydown and keyup events. Try the onkeyup=checkEnter instead of onkeypress. I just tested that and it works.

出于某种原因,IE6将无法检测到按下按键事件的ENTER。但它确实在keydown和keyup事件上检测到ENTER。尝试onkeyup = checkEnter而不是onkeypress。我刚测试了它,它的工作原理。

EDIT: According to this quirksmode article, Keypress fires when actual characters are being inserted. keyup/keydown fire on all keys. However, this behavior is different in FF and IE8.

编辑:根据这篇quirksmode文章,Keypress在插入实际字符时触发。 keyup / keydown触发所有键。但是,这种行为在FF和IE8中是不同的。

#1


For some reason IE6 won't detect pressing ENTER on the keypress event. It does however detect ENTER on the keydown and keyup events. Try the onkeyup=checkEnter instead of onkeypress. I just tested that and it works.

出于某种原因,IE6将无法检测到按下按键事件的ENTER。但它确实在keydown和keyup事件上检测到ENTER。尝试onkeyup = checkEnter而不是onkeypress。我刚测试了它,它的工作原理。

EDIT: According to this quirksmode article, Keypress fires when actual characters are being inserted. keyup/keydown fire on all keys. However, this behavior is different in FF and IE8.

编辑:根据这篇quirksmode文章,Keypress在插入实际字符时触发。 keyup / keydown触发所有键。但是,这种行为在FF和IE8中是不同的。