HTML< input type ='file'>文件选择事件 [英] HTML <input type='file'> File Selection Event
本文介绍了HTML< input type ='file'>文件选择事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我们有以下代码:
<形式行动= '' 方法= 'POST' 是enctype ='多/格式数据'>
< input type ='file'name ='userFile'>< br>
< input type ='submit'name ='upload_btn'value ='upload'>
< / form>
结果如下:
< img src =https://i.stack.imgur.com/bT2hc.pngalt =图片显示浏览和上传按钮>
当用户点击'浏览...'按钮,打开一个文件搜索对话框:
用户将通过双击文件或点击'打开'按钮。
是否有Javascript事件可以在选择文件之后通知我?
解决方案
收听变更事件。
input.onchange = function(e){
..
};
Let's say we have this code:
<form action='' method='POST' enctype='multipart/form-data'>
<input type='file' name='userFile'><br>
<input type='submit' name='upload_btn' value='upload'>
</form>
which results in this:
When the user clicks the 'Browse...' button, a file search dialog box is opened:
The user will select the file either by double-clicking the file or by clicking the 'Open' button .
Is there a Javascript Event that I can use to be notified after after the file is selected?
解决方案
Listen to the change event.
input.onchange = function(e) {
..
};
这篇关于HTML< input type ='file'>文件选择事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文