Html 提交按钮不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16052454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Submit button doesn't work
提问by dhblah
I have a form with <input type="submit"
. In chrome submit doesn't do anything. On a "network" in tab in developer tools I see nothing. No errors in developer tools either. Meanwhile, if I do save a page and open a saved page, then after I press submit button, I see something appears in "network" tab. This happens in chrome and firefox. This works as expected in IE.
我有一个带有<input type="submit"
. 在 chrome 中提交不做任何事情。在开发人员工具选项卡中的“网络”上,我什么也看不到。开发人员工具中也没有错误。同时,如果我确实保存了一个页面并打开了一个保存的页面,那么在我按下提交按钮后,我会看到“网络”选项卡中出现了一些东西。这发生在 chrome 和 firefox 中。这在 IE 中按预期工作。
Does anybody have a hindsight, what should I look at?
有没有人有后见之明,我应该看什么?
EDIT: I don't need a direct answer, I only need to know, where should I look at. If someone posts a direction and that'll help me to solve my problem, I'll accept it as a correct answer.
编辑:我不需要直接回答,我只需要知道,我应该在哪里看。如果有人发布了一个方向并且可以帮助我解决我的问题,我会接受它作为正确答案。
EDIT2: Structure of a page looks like this:
EDIT2:页面结构如下所示:
html
head
body
div
div
form
form
form
form
form
input
input
table
table
tbody
tr..td..input type=submit
EDIT3: We found the actual problem, it was that in a page was a link, containing href="#"
and after clicking on that link submit stopped to work, because #
was added to the end of URL and because action
of the form was empty so it picked up URI from current URI, which contained #
at the, so instead of submitting, browser did jump on a current page.
EDIT3:我们发现了实际的问题,它是在一个页面中有一个链接,包含href="#"
并在点击该链接后提交停止工作,因为#
被添加到 URL 的末尾并且因为action
表单是空的所以它拿起了 URI从包含#
在的当前 URI 中,浏览器没有提交,而是跳转到当前页面。
回答by lukeocom
If you are not using any javascript/jquery for form validation, then a simple layout for your form would look like this.
如果您没有使用任何 javascript/jquery 进行表单验证,那么您的表单的简单布局将如下所示。
within the body of your html document:
在您的 html 文档正文中:
<form action="formHandler.php" name="yourForm" id="theForm" method="post">
<input type="text" name="fname" id="fname" />
<input type="submit" value="submit"/>
</form>
You need to ensure you have the submit button within the form tags, and an appropriate action assigned. Such as sending to a php file.
您需要确保在表单标签中有提交按钮,并分配了适当的操作。比如发送到一个php文件。
For a more direct answer, provide the code you are working with.
要获得更直接的答案,请提供您正在使用的代码。
You may find the following of use: http://www.w3.org/TR/html401/interact/forms.html
您可能会发现以下用法:http: //www.w3.org/TR/html401/interact/forms.html
回答by Jyothu
Are you using HTML5? If so, check whether you have any <input type="hidden">
in your form with the property required
. Remove that required
property. Internet Explorer won't take this property, so it works but Chrome will.
你在使用 HTML5 吗?如果是这样,请检查<input type="hidden">
您的表单中是否有任何属性required
。删除该required
属性。Internet Explorer 不会接受这个属性,所以它可以工作,但 Chrome 会。
回答by Dan Csharpster
Check if you are using any sort of jquery/javascript validation on the page and try disabling it and see what happens. You can use your browser's developer tools to see if any javascript file with validate or validation is being loaded. You can also look for hidden form elements (ie. style set to display:none; or something like that) and make sure there isn't a hidden validation error on those that's not being rendered.
检查您是否在页面上使用任何类型的 jquery/javascript 验证并尝试禁用它,看看会发生什么。您可以使用浏览器的开发人员工具查看是否正在加载任何带有验证或验证的 javascript 文件。您还可以查找隐藏的表单元素(即样式设置为 display:none; 或类似的东西)并确保未呈现的那些元素没有隐藏的验证错误。
回答by Ali
I faced this problem today, and the issue was I was preventing event default action in document onclick:
我今天遇到了这个问题,问题是我阻止了文档 onclick 中的事件默认操作:
document.onclick = function(e) {
e.preventDefault();
}
Document onclick usually is used for event delegation but it's wrong to prevent default for every event, you must do it only for required elements:
文档 onclick 通常用于事件委托,但阻止每个事件的默认值是错误的,您必须仅对必需元素执行此操作:
document.onclick = function(e) {
if (e.target instanceof HTMLAnchorElement) e.preventDefault();
}
回答by MattJHoughton
Hello from the future.
来自未来的你好。
For clarity, I just wanted to add (as this was pretty high up in google) - we can now use
为了清楚起见,我只想添加(因为这在谷歌中非常高) - 我们现在可以使用
<button type="submit">Upload Stuff</button>
<button type="submit">Upload Stuff</button>
And to reset a form
并重置表格
<button type="reset" value="Reset">Reset</button>
<button type="reset" value="Reset">Reset</button>
Check out button types
查看按钮类型
We can also attach buttons to submit forms like this:
我们还可以将按钮提交表单就像这样:
<button type="submit" form="myform" value="Submit">Submit</button>
<button type="submit" form="myform" value="Submit">Submit</button>
回答by Adron
I ran into this on a friend's HTML code and in his case, he was missing quotes.
我在朋友的 HTML 代码上遇到了这个问题,在他的情况下,他缺少引号。
For example:
例如:
<form action="formHandler.php" name="yourForm" id="theForm" method="post">
<input type="text" name="fname" id="fname" style="width:90;font-size:10>
<input type="submit" value="submit"/>
</form>
In this example, a missing quote on the input text fname will simply render the submit button un-usable and the form will not submit.
在此示例中,输入文本 fname 上缺少引号只会使提交按钮无法使用,并且表单将不会提交。
Of course, this is a bad example because I should be using CSS in the first place ;) but anyways, check all your single and double quotes to see that they are closing properly.
当然,这是一个不好的例子,因为我应该首先使用 CSS ;) 但是无论如何,请检查所有单引号和双引号以查看它们是否正确关闭。
Also, if you have any tags like center, move them out of the form.
此外,如果您有任何标签,如中心,请将它们移出表单。
<form action="formHandler.php" name="yourForm" id="theForm" method="post">
<center> <-- bad
As strange it may seems, it can have an impact.
看起来很奇怪,但它会产生影响。