如何确定用户是否选择文件上传文件? [英] How to determine if user selected a file for file upload?

查看:101
本文介绍了如何确定用户是否选择文件上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有

If I have a

<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
}

这篇关于如何确定用户是否选择文件上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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