When a text input has focus and the enter key is pressed, document.activeElement.nodeName
should return INPUT
. This works in Chrome, Firefox and Safari, but in Internet Explorer/Edge it returns BUTTON
.
当文本输入具有焦点并按下回车键时,document.activeElement.nodeName应返回INPUT。这适用于Chrome,Firefox和Safari,但在Internet Explorer / Edge中,它会返回BUTTON。
I'm working on a custom form with heavy JavaScript and Internet Explorer reports the incorrect nodeName, which is causing a big problem.
我正在处理一个带有大量JavaScript的自定义表单,而Internet Explorer报告错误的nodeName,这导致了一个大问题。
See this fiddle for the example.
看到这个小提琴的例子。
Is this a known issue? Is there a workaround or fix for this?
这是一个已知的问题?是否有解决方法或修复此问题?
1 个解决方案
#1
0
If you change the method to output outerHTML
, you can see that the text input has focus in Chrome, but the submit input has focus in IE.
如果您更改方法以输出outerHTML,您可以看到文本输入在Chrome中具有焦点,但提交输入在IE中具有焦点。
Binding the event to keydown
instead of keyup
or changing the second input
from submit
to button
seems to work. Pressing enter
in a form is supposed to activate the first submit
input, and I guess one of the things IE does when it handles this is to give focus to the submit
input.
将事件绑定到keydown而不是keyup或将第二个输入从submit更改为按钮似乎有效。在表单中按Enter键应该激活第一个提交输入,我想IE处理它时所做的事情之一是将焦点放在提交输入上。
keydown
probably works because that event is raised before IE activates the submit
button.
keydown可能有效,因为在IE激活提交按钮之前会引发该事件。
#1
0
If you change the method to output outerHTML
, you can see that the text input has focus in Chrome, but the submit input has focus in IE.
如果您更改方法以输出outerHTML,您可以看到文本输入在Chrome中具有焦点,但提交输入在IE中具有焦点。
Binding the event to keydown
instead of keyup
or changing the second input
from submit
to button
seems to work. Pressing enter
in a form is supposed to activate the first submit
input, and I guess one of the things IE does when it handles this is to give focus to the submit
input.
将事件绑定到keydown而不是keyup或将第二个输入从submit更改为按钮似乎有效。在表单中按Enter键应该激活第一个提交输入,我想IE处理它时所做的事情之一是将焦点放在提交输入上。
keydown
probably works because that event is raised before IE activates the submit
button.
keydown可能有效,因为在IE激活提交按钮之前会引发该事件。