How to determine if user selected a file for file upload?(如何确定用户是否选择了文件进行文件上传?)
问题描述
如果我有一个
<input id="uploadFile" type="file" />
标签和提交按钮,我如何在 IE6(及更高版本)中确定用户是否选择了文件.
tag, and a submit button, how do I determine, in IE6 (and above) if a file has been selected by the user.
在 FF 中,我只是这样做:
In FF, I just do:
var selected = document.getElementById("uploadBox").files.length > 0;
但这在 IE 中不起作用.
But that doesn't work in IE.
推荐答案
这适用于 IE(我相信还有 FF):
This works in IE (and FF, I believe):
if(document.getElementById("uploadBox").value != "") {
// you have a file
}
这篇关于如何确定用户是否选择了文件进行文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!