gpt4 book ai didi

jQuery 提交不适用于

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:37 24 4
gpt4 key购买 nike

我正在尝试使链接提交表单。为什么当我将提交输入元素命名为 submit 时,链接不再有效?

 //breaks form submission
<input type="submit" value="Submit" name="submit" />

//does not break form submission
<input type="submit" value="Submit" name="xsubmit" />

在 Chrome 中,我收到以下错误。

Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function

不工作

<p>Type 'correct' to validate.</p>
<form method="post" enctype="multipart/form-data">
<input type="submit" value="Submit" name="submit" />

<a id="btn_submit">
<span id="txt_submit">Submit</span>
</a>
</form>

<script>

$("#btn_submit").click(function() {
$("form").submit();
});

$("form").submit(function() {

});
</script>

工作

 <p>Type 'correct' to validate.</p>
<form method="post" enctype="multipart/form-data">
<input type="submit" value="Submit" name="xsubmit" />

<a id="btn_submit">
<span id="txt_submit">Submit</span>
</a>
</form>

<script>

$("#btn_submit").click(function() {
$("form").submit();
});

$("form").submit(function() {

});
</script>

最佳答案

“提交”是一个保留字。它与javascript冲突。只需将输入的名称更改为其他名称即可。

来自关于方法的 jQuery 文档 submit() :

Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint.

关于jQuery 提交不适用于 <a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com