<form class="myform" action="mail.php">
Your name:<br>
<input type="text" name="myform-name"><br><br>
Your file:<br>
<input type="file" name="myform-file"><br><br>
<button type="submit">Submit</button>
</form>
如何直接从代码中使用vanilla javascript(不是jQuery)提交此表单(无需用户交互)?
答案 0 :(得分:3)
您可以使用:
document.getElementsByTagName('form')[0].submit()
答案 1 :(得分:1)
只需在代码中添加表单名称:
<form name="myform" class="myform" action="mail.php">
Your name:<br>
<input type="text" name="myform-name"><br>
<button type="submit">Submit</button>
</form>
从javascript提交来自:
<script type="text/javascript">document.myform.submit();</script>
答案 2 :(得分:0)