[英]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.