由于隐藏按钮,Enter不会在IE中提交表单

Sjo*_*erd 9 javascript internet-explorer autocomplete submit

我有一个带有两个按钮的表单.第一个是使用Javascript隐藏的.

当我在IE中的文本字段中按Enter键时,表单不会提交.我认为这是因为它选择了第一个按钮作为默认提交按钮,但由于该按钮被隐藏,它不起作用.

我通过在enter keydown Javascript事件上提交表单来解决这个问题.但是,如果用户按Enter键从浏览器的自动完成下拉菜单中选择一个项目,这也会提交表单.

示例自动完成下拉列表

如何在不影响自动完成功能的情况下在IE中输入表单?

小智 12

尝试使用以下类隐藏按钮:

.hidden-element {
  width: 0px;
  height: 0px;
  position: absolute;
  top: -99999px;
  left: -99999px;
}
Run Code Online (Sandbox Code Playgroud)

  • @Charlie我不同意.其他人可能会发现此特定评论有用. (7认同)

Chr*_*her 6

We had a similar problem a few years ago, and AFAIR, we added an additional button to the beginning of the form, which always performs the default submit action when enter is pressed in IE. That button can be "almost hidden" by giving it a 1x1 transparent image.


Omi*_*mid 5

我通过不透明度0固定它,如:

<input type="submit" style="width: 0px; height: 0px; opacity: 0;" id="submitBtn" name="submitBtn">
Run Code Online (Sandbox Code Playgroud)