Let's say I have this form in my page
假设我的页面中有此表单
<form id="myform" action="src/post.php" name="post" method="post" target="_blank">
<div id="editor"></div>
</form>
Which works flawlessly. But I need to use a button from another location in the same file to submit that form by ID. It's like a trigger command, but I believe it can only be achieved by Javascript.
哪个完美无瑕。但我需要使用同一文件中其他位置的按钮按ID提交该表单。这就像一个触发命令,但我相信它只能通过Javascript来实现。
3 个解决方案
#1
1
Try next code
试试下一个代码
document.forms['post'].submit();
#2
0
Assuming you have a button with id submitButton
, this should do the trick
假设你有一个id为submitButton的按钮,这应该可以解决问题
<button id="submitButton">Submit</button>
You could do
你可以做到
$('#submitButton').on('click', function() {
$('form').submit();
});
#3
0
I could make it work, but it seems that when I submit the form from another location it is not including the <div id="editor">
that is withing the form and that's why I'm getting a blank page.
我可以使它工作,但似乎当我从另一个位置提交表单时,它不包括
#1
1
Try next code
试试下一个代码
document.forms['post'].submit();
#2
0
Assuming you have a button with id submitButton
, this should do the trick
假设你有一个id为submitButton的按钮,这应该可以解决问题
<button id="submitButton">Submit</button>
You could do
你可以做到
$('#submitButton').on('click', function() {
$('form').submit();
});
#3
0
I could make it work, but it seems that when I submit the form from another location it is not including the <div id="editor">
that is withing the form and that's why I'm getting a blank page.
我可以使它工作,但似乎当我从另一个位置提交表单时,它不包括