本文介绍了当按钮名称为“提交"时,表单提交按钮将不会提交;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当提交按钮的名称属性恰好是提交"时,我无法提交表单.

I am having trouble getting a form to submit when the name attribute of the submit button is precisely "submit".

代码如下:

<input onclick="checkForm(document.form_29) && document.form_29.submit();"value="Submit" name="submit" type="button">

请注意,我们没有使用提交"的标准输入类型,而是使用按钮"的输入类型,并在验证脚本 (checkForm) 返回 true 后使用 JavaScript 提交表单.

Note that we are not using a standard input type of "submit", but rather an input type of "button" with JavaScript being used to submit the form after a validation script (checkForm) has returned true.

奇怪的是,当且仅当 name 属性为提交"时,这将不起作用.该问题区分大小写,因此以下(以及任何其他命名,包括无 name 属性)将起作用:

The odd thing is that this will not work if and only if the name attribute is "submit". The problem is case-sensitive, so the following (and any other naming, including no name attribute) will work:

<input onclick="checkForm(document.form_29) && document.form_29.submit();"value="Submit" name="Submit" type="button">

我一直在查看 W3C 规范中提到的保留名称,但我找不到任何内容.我怀疑我在这里忽略了一些非常明显的东西,所以我希望你们中的一些人能看到我看不到的东西.

I have been looking over the W3C specs for some mention of a reserved name, but I could not find anything. I suspect I am overlooking something really obvious here, so I'm hoping some of y'all out there can see something I can't.

感谢您的帮助.

推荐答案

您遇到问题,因为 namesubmit 覆盖了 form.submit() 那个 的函数引用,而不是 form_29.submit 引用那个按钮,而不是 DOM submit()代码>函数.

You're having issues because the name being submit is overriding the form.submit() function reference for that <form>, instead form_29.submit refers to that button, rather than the DOM submit() function.

这篇关于当按钮名称为“提交"时,表单提交按钮将不会提交;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 04:05
查看更多