我想通过 jquery/javascript 提交表单,为此我使用 javascript (document.getElementById('formId').submit(); ) 但我们得到错误:
file.php:144 Uncaught TypeError: document.getElementById(...).submit is not a function at HTMLDocument.<anonymous> (file.php:144) at fire (jquery.js:3048) at Object.fireWith [as resolveWith] (jquery.js:3160) at Function.ready (jquery.js:433) at HTMLDocument.completed (jquery.js:104)
我发现如果我在表单中使用 HTML 标签,则会出现错误 HTML 标签如:
<ul class="pager">
<li class="next" >
如果我以过度形式删除这些标签,那么它就可以正常工作
<form action="" name="formId" id="formId" method="post" >
<fieldset class='panel ques' style='margin:5%;' id='ques_1' >
Question 1 :: what is command for changing user information??</b><br /><br />
<input type="radio" name="a" value="a" checked>
<label for="55892169d2efc"> usermod</label><br /><br />
<input type="radio" name="b" value="b">
<label for="55892169d2f05"> useradd</label><br /><br />
<input type="radio" name="c" value="c">
<label for="55892169d2f09"> useralter</label><br /><br />
<input type="radio" name="d" value="d">
<label for="55892169d2f0c"> groupmod</label><br /><br />
<ul class="pager">
<li class="next" >
<button type="text" style="float: right;" name="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Finish
</button>
</li>
</ul>
</fieldset>
</form>
<script type="text/javascript">
document.getElementById('formId').submit();
</script>
最佳答案
您将提交按钮命名为 submit
,它覆盖了 form
的 submit()
方法。重命名按钮可以解决该问题。
因此,作为一般最佳实践,不要为事物命名或提供与对象、属性或方法名称相匹配的 ID。
<form action="http://example.com" name="formId" id="formId" method="post" >
<fieldset class='panel ques' style='margin:5%;' id='ques_1' >
Question 1 :: what is command for changing user information??<br><br>
<input type="radio" name="a" value="a" checked>
<label for="55892169d2efc"> usermod</label><br><br>
<input type="radio" name="b" value="b">
<label for="55892169d2f05"> useradd</label><br><br>
<input type="radio" name="c" value="c">
<label for="55892169d2f09"> useralter</label><br><br>
<input type="radio" name="d" value="d">
<label for="55892169d2f0c"> groupmod</label><br><br>
<ul class="pager">
<li class="next" >
<button type="text" style="float: right;" name="btnSubmit" class="btn btn-primary">
<span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Finish
</button>
</li>
</ul>
</fieldset>
</form>
<script>
document.getElementById('formId').submit();
</script>
关于javascript - 未捕获的 TypeError : document. getElementById(...).submit 不是 HTMLDocument 中的函数。<anonymous>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57260673/