【发布时间】:2011-08-22 11:31:28
【问题描述】:
【问题讨论】:
【问题讨论】:
使用 HTML5,您可以使用 JavaScript 在客户端实现此目的。这是 jQuery,但它当然也可以正常工作:http://jsfiddle.net/pimvdb/S4mEv/2/。请注意,它并非在所有浏览器中都可用(目前)。
$('#file').change(function() {
alert(this.files[0].size + " bytes");
});
【讨论】:
你可以使用Uploadify,它是一个jQuery 插件,使用flash 来检查文件大小并具有其他简洁的功能。 http://www.uploadify.com/documentation/options/sizelimit/
【讨论】:
你可以做那个文件 HTML5 JS File API
您可以在我的 Web IDE 中测试运行以下代码(但请使用 google chrome 或 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.');
}
【讨论】:
Gmail 为此使用了 Flash 应用程序。如果要检查文件大小,则需要在这样的环境中执行此操作; JavaScript 本身并没有实现这一点的机制。
【讨论】:
<input type=file> 中选择文件时,您可以使用onchange 事件并查找所选文件。还包括文件大小。 developer.mozilla.org/en/DOM/File