gpt4 book ai didi

javascript - 对象 # 的属性 'submit' 不是函数

转载 作者:IT王子 更新时间:2023-10-29 02:59:55 26 4
gpt4 key购买 nike

谁能给我解释一下这个错误是什么意思?如果对此有任何帮助,我将不胜感激。

<form class="form" id="form" action="/mailer.php" method="post">

我为此使用的 Jquery 代码是这样的。

$('#form').submit();  

最佳答案

检查表单以查看是否有一个 HTMLInputElement id 或名称是 submit

这会给HTMLFormElement设置一个属性submit,所以表单元素原型(prototype)中的submit函数不能被执行。

示例:

<form class="form" id="form" action="/mailer.php" method="post">
​<input type="button" name="submit" value="go"/>
</form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

js:

​console.log($("#form")[0].submit)​;​  // will be the button element, not the submit function.

jQuery 的 .submit() 方法会在原始 dom 元素上调用 .submit(),所以会发生错误。

关于javascript - 对象 #<HTMLFormElement> 的属性 'submit' 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12540953/

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