2011-08-22 34 views

回答

0

Gmail爲此使用Flash應用程序。如果你想檢查文件大小,你需要在這樣的環境下做到這一點;單獨使用JavaScript沒有任何機制可以實現這一點

+2

與HTML5結合使用。當用戶在''中選擇一個文件時,可以使用'onchange'事件並查找所選文件。還包括文件大小。 https://developer.mozilla.org/en/DOM/File – pimvdb

+0

有趣,很高興知道。您可以考慮將其添加爲備用答案。 – cdhowie

+0

一旦看到hotmail網站。由.net開發的總網站,在該網站上傳文件時顯示的警告與我想要的一樣。 – Swaroop

1

你能做到這一點的文件HTML5 JS文件API

你可以在我的網頁IDE試運行下面的代碼(但請使用谷歌瀏覽器或FF): http://codesocialist.com/#/?s=bN

以下代碼將爲您檢索文件類型和文件大小:)

<input type="file" id="files" name="files[]" multiple /> 
<output id="list"></output> 

// Check for the various File API support. 
if (window.File && window.FileReader && window.FileList && window.Blob) { 

    // Great success! All the File APIs are supported. 
    function handleFileSelect(evt) { 
     var files = evt.target.files; // FileList object 

     // files is a FileList of File objects. List some properties. 
     var output = []; 
     for (var i = 0, f; f = files[i]; i++) { 
      output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ', f.size, ' bytes </strong></li>'); 
     } 

     document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>'; 
    } 

    // Bind Event Listener 
    document.getElementById('files').addEventListener('change', handleFileSelect, false); 

} else { 
    alert('The File APIs are not fully supported in this browser.'); 
} 
+1

如果問題重複,請將它們標記爲這樣。請不要複製和粘貼你的答案。複製和粘貼在編程中是不好的,爲什麼它會對編程有所幫助? –