您的位置:首页 > 其它

IE11下获取<input type="file">的文件名

2015-11-11 12:30 591 查看
参考:https://msdn.microsoft.com/zh-cn/subscriptions/hh772931(v=vs.85)
<!DOCTYPE html>
<html >
<head>
<title>Files property test</title>
<script type="text/javascript">
function getFiles() {
// Get input element
myFileList = document.getElementById("myfiles");
// loop through files property, using length to get number of files chosen
for (var i = 0; i < myFileList.files.length; i++) {
// display them in the div
document.getElementById("display").innerHTML += "<br/>" + myFileList.files[i].name ;
}
}
</script>
</head>
<body>
<label>Use <strong>shift</strong> or <strong>ctrl</strong> click to pick a few files:
<input type="file" multiple id="myfiles" onchange="getFiles();" /></label>

<div id="display"></div>
</body>
</html>
可以获取文件名,但是不能获取路径。IE11、FF可用[/code]
获取路径需要修改IE安全性设置,步骤是:  工具 -> Internet选项 -> 安全 -> 自定义级别 -> 找到“其他”中的“将本地文件上载至服务器时包含本地目录路径”,选中“启用”即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: