问题描述
我试图找出与所描述的行为有关的事情。我有一个带有单个输入文本字段的表单,以及一个提交按钮。与问这个问题的人不同,我希望在用户点击输入时提交表单。确实,这对我很有用;然而,不起作用的是,导致表单中的提交输入被虚拟点击的怪癖:Firefox和Chrome在发布的参数中包含提交输入的名称,而IE没有。换句话说,我希望这种古怪的提交行为能够发布文本输入字段和提交输入。
有趣的是,我的表单正在做这件事直到我最近介绍的一些神秘变化。 (Firefox和Chrome仍然可以工作,但IE曾经工作过,现在没有。)我大概可以弄清楚我改变了什么来打破它,但是@ bobince似乎理解了我想要看的这个怪癖如果有已知(甚至可能是文档)的方式来控制它。
这是我的测试页面:
这是一个简单的测试,可以弥补:
<!DOCTYPE html>
< html>
< body>
< form name ='foo'action ='cgi / echoparams.cgi'method ='post'>
< input type ='text'name ='name'value =''>
< input type ='submit'name ='submit_button'value ='提交'>
< / form>
< / body>
< / html>
cgi脚本只是鹦鹉回来的内容。
是的,抱歉,这不是可以直接解决的。我不知道你之前的工作案件是什么,但我怀疑可能有额外的投入。 (只有当有单个文本输入时才会出现异常行为。)
由于历史地雷围绕着是否默认提交按钮是'成功'的问题,最好不要依赖它。添加隐藏的输入来表示提交,并省略提交按钮上的名称
。将任何提交脚本提交到表单onsubmit
而不是默认按钮。
如果您有其他提交按钮用于不同的操作(例如编辑vs删除),然后使第一个按钮执行'默认'操作并设置无名称,然后添加名称
/ 值
s覆盖其他按钮上的默认行为。如果点击,这些肯定会'成功'(并会收到
点击
事件)。
I'm trying to figure out something having to do with the behavior descibed by this old question from last year. I've got a form with a single input text field, and a single "submit" button. Unlike the person who asked that question, I want the form to submit when the user hits "enter". Indeed, that's working for me; what's not working however is the quirk that causes a "submit" input in the form to be virtually clicked: Firefox and Chrome include the "submit" input's name in the parameters posted, while IE does not. In other words, I want this quirky submit behavior to post the text input field, and the submit input too.
The funny thing is that my form was doing just that up until some mystery change I introduced recently. (Firefox and Chrome do still work, but IE once worked and now doesn't.) I can probably figure out what I changed to break it, but as @bobince seemed to understand something about this quirk I figured I'd ask to see if there are known (possibly even documented) ways to control it.
Here's my test page: http://gutfullofbeer.net/post.html
It's about as simple a test as I could make up:
<!DOCTYPE html>
<html>
<body>
<form name='foo' action='cgi/echoparams.cgi' method='post'>
<input type='text' name='name' value=''>
<input type='submit' name='submit_button' value='Submit'>
</form>
</body>
</html>
The cgi script just parrots back the posted content.
解决方案 Yeah, sorry, it's not directly fixable. I don't know what your previous ‘working’ case was, but I suspect there might have been an extra input present. (It's only when there's a single text input that the exceptional behaviour occurs.)
With the historical mines around the question of whether a default-submit button is ‘successful’, it's better never to rely on it. Add the hidden input to signify a submission and omit the name
on the submit button. Put any submission scripting on form onsubmit
rather than the default button.
If you have additional submit buttons for different actions (eg. Edit vs Delete), then make the first button perform the ‘default’ action and set no name, then add name
/value
s that override the default behaviour on the other buttons. These are sure to be ‘successful’ (and will receive a click
event) if clicked.
这篇关于击中“输入”当表单具有“提交”字段时从输入(文本)字段输入。输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!