![](/img/trans.png)
[英]Firefox/IE IIS 6 Not Supporting Hiding Lables in Javascript/HTML
[英]Why IE 9 not supporting JavaScript function?
我正在尝试提供一种在运行时检查文件大小和扩展名的功能,我已经做到了,并且可以在除9外的所有浏览器上正常工作。有人可以让我知道问题出在哪里吗?
<script type='text/javascript'>
function showFileSize() {
var input, file;
// (Can't use `typeof FileReader === "function"` because apparently
// it comes back as "object" on some browsers. So just see if it's there
// at all.)
if (!window.FileReader) {
bodyAppend("p", "The file API isn't supported on this browser yet.");
return;
}
input = document.getElementById('fileinput');
if (!input.files[0]) {
bodyAppend("p", "Please select a file before clicking 'Load'");
}
else {
file = input.files[0];
var sFileName = file.name;
var sFileExtension = sFileName.split('.')[sFileName.split('.').length - 1].toLowerCase();
bodyAppend("p", "File Type " + sFileExtension + " is " + file.size + " bytes in size");
}
}
function bodyAppend(tagName, innerHTML) {
var elm;
elm = document.createElement(tagName);
elm.innerHTML = innerHTML;
document.body.appendChild(elm);
}
</script>
<form action='#' onsubmit="return false;">
<input type='file' id='fileinput'>
<input type='button' id='btnLoad' value='Save' onclick='showFileSize();'>
</form>
IE9不支持HTML5 File API,包括FileReader()
。
一种可能的解决方法是polyfill,下面的解决方案使用Flash在不支持File API(IE和Safari) 但不支持drag-n-drop的浏览器上提供对文件系统的访问。
而是克隆输入,将克隆放置在原始副本的位置,然后将原始副本移动到隐藏的形式。 您可能需要为此使用iframe。
当然可以,但是需要一些编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.