Nat*_*ate 165 javascript
我有一个id为id的表单,theForm
其中包含以下div,其中包含一个提交按钮:
<div id="placeOrder"
style="text-align: right; width: 100%; background-color: white;">
<button type="submit"
class='input_submit'
style="margin-right: 15px;"
onClick="placeOrder()">Place Order
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
单击时,将placeOrder()
调用该函数.该函数将上面div的innerHTML更改为"processing ..."(因此提交按钮现在消失了).
上面的代码有效,但现在的问题是我无法提交表单!我试过把它放在placeOrder()
函数中:
document.theForm.submit();
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
我怎样才能提交表格?
And*_*are 123
将name
表单的属性设置为"theForm"
,您的代码将起作用.
ale*_*lex 93
您可以使用...
document.getElementById('theForm').submit();
Run Code Online (Sandbox Code Playgroud)
...但不要取代innerHTML
.您可以隐藏表单,然后插入一个处理... span
将显示在其位置.
var form = document.getElementById('theForm');
form.style.display = 'none';
var processing = document.createElement('span');
processing.appendChild(document.createTextNode('processing ...'));
form.parentNode.insertBefore(processing, form);
Run Code Online (Sandbox Code Playgroud)
Chi*_*mar 32
document.getElementById("form1").submit();
Run Code Online (Sandbox Code Playgroud)
在我的情况下它完美无缺.
你也可以在功能上使用它,比如
function formSubmit()
{
document.getElementById("form1").submit();
}
Run Code Online (Sandbox Code Playgroud)
小智 14
<html>
<body>
<p>Enter some text in the fields below, and then press the "Submit form" button to submit the form.</p>
<form id="myForm" action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Submit form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 10
document.forms["name of your form"].submit();
Run Code Online (Sandbox Code Playgroud)
要么
document.getElementById("form id").submit();
Run Code Online (Sandbox Code Playgroud)
你可以尝试任何这个...这将是肯定的工作..
小智 9
我将离开我提交表单的方式,而不使用表单中的name
标签:
<button type="submit" onClick="placeOrder(this.form)">Place Order</button>
Run Code Online (Sandbox Code Playgroud)
function placeOrder(form){
form.submit();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
<!-- change id attribute to name -->
<form method="post" action="yourUrl" name="theForm">
<button onclick="placeOrder()">Place Order</button>
</form>
Run Code Online (Sandbox Code Playgroud)
function placeOrder () {
document.theForm.submit()
}
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码通过 JavaScript 提交表单:
document.getElementById('FormID').submit();
Run Code Online (Sandbox Code Playgroud)