如何提交“文件”?使用JavaScript输入没有提交按钮? [英] How do I submit a "file" input without submit button using JavaScript?

查看:72
本文介绍了如何提交“文件”?使用JavaScript输入没有提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在不点击提交按钮的情况下自动提交表单吗?

There is a way to automatically submit a form without clicking to a "submit" button?

我有一个带有一个文件输入的表单。我会在用户选择一个文件后提交表单。

I have a form with one "file" input. I would submit the form after the user have selected one file.

推荐答案

是的,你可以使用form.submit()函数。在文件输入上添加一个onchange监听器并将其链接到form.submit函数,如下所示:

yes, you can use the form.submit() function. Add an onchange listener on the file input and link it to the form.submit function, like so:

<form action="upload.php" method="post">
<input type="file" onchange="this.form.submit()" name="myFile"/>
</form>

这篇关于如何提交“文件”?使用JavaScript输入没有提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆