IE 中的提交按钮行为
我在 IE 中遇到问题。当焦点位于最后一个输入控件上时按 Enter 键会将焦点发送到“下一步”按钮。这样就提交了表单。到目前为止,一切都很好。
我的基类 WizardController 中的代码查看“下一步提交”按钮是否为 null,如下所示:
protected string NextButton
{
get
{
return ControllerContext.HttpContext.Request.Params["NextButton"];Nex
}
}
但是,尽管提交了表单,但除非用户用鼠标显式单击该按钮,否则该属性将返回 null。
这是明显错误的,但我不知道为什么会发生这种情况。
编辑以具体说明问题:
仅当 HTML 表单中只有一个呈现给浏览器的文本输入控件时,才会出现此问题。
编辑结束
安德鲁
I have a problem in IE. Hitting enter when the focus is on the last input control sends the focus to the "Next" button. This submits the form. So far, so good.
The code in my base class WizardController looks to see if the Next submit button is null, as follows:
protected string NextButton
{
get
{
return ControllerContext.HttpContext.Request.Params["NextButton"];Nex
}
}
However, despite the form submitting, this property returns null unless the user explicitly clicks on the button with his mouse.
This is blatantly wrong, but I have no idea why it is happening.
EDITED TO SPECIFY THE PRECISE PROBLEM:
The problem only occurs IF there is ONLY one TEXT input control in the HTML form that gets rendered to the browser.
END EDIT
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于找到了对我的问题的解释:
这似乎是 IE 中的一个错误,如果渲染的 HTML 表单中只有一个文本输入,那么 IE 将无法正确提交表单。该问题(简要)描述于:
使用IE时通过回车键提交表单
在上面的链接中,没有说明为什么会出现该错误,也没有说明从什么版本的IE开始,所以最好是一揽子解决方案。
文章中建议的解决方法是添加一个 css 隐藏文本输入(带有 IE 的条件):
这对我有用,所以问题解决了。
以下内容是为了记录我遇到的问题:
与文章中描述的问题不同,我的表单确实提交了。但是,当我尝试通过按 Tab 或 Enter 键来检查哪个按钮已被访问时,HttpContext.Request.Params 集合中没有提交按钮。所以我看到的行为略有不同。
上面的文章确实指出,这种行为仅在只有一个文本输入控件时才会出现。例如,单个复选框不会导致问题。
我希望这篇文章能充分记录这个问题......并且微软有一天会纠正这个错误。
I have finally found an explanation for my problem:
It seems to be a bug in IE, whereby if there is a single text input in the rendered HTML form, then IE will not submit the form properly. The issue is described (briefly) at:
Form Submit via Enter Key when using IE
In the above link, no description is given as to why the bug occurs, or since what version of IE, so a blanket solution is better.
The workaround suggested in the article is to add a css hidden text input (with conditionals for IE):
This worked for me, so issue solved.
The following is included to document the issue as I experienced it:
Unlike the problem described in the article, my form did submit. However, when I tried to check which button had been accessed by hitting tab or enter key, no submit button was in the HttpContext.Request.Params collection. So the behaviour I saw was slightly different.
What the above article did identify is that this behaviour is only seen WHEN there is ONLY one text input control. A single check box, for example, does not cause the problem.
I hope that this documents the problem adequately... and that MS will one day correct the bug.
一个简单的解决方法可能是使用隐藏的表单元素并依赖它而不是按钮。
如果您有多个按钮,您始终可以在提交之前使用 JavaScript 更改操作元素的值。
A simple work around might be to use a hidden form element and depend on that rather than the button.
If you have multiple buttons you can always use JavaScript to change the value of the action element just before submitting.