具体代码:
HTML:
1 <input type="file" id="File1" name="File1" onchange="loadFile(this)">
JS:
1 function loadFile(doc) { 2 //alert("你的文件大小为:" + (doc.files[0].size / 1024).toFixed(0) + "kb"); 3 if (doc.files && doc.files[0]) { 4 if ((Math.round(doc.files[0].size / 1024 / 1024 * 100) / 100 > 100)) { 5 var file = $("#File1"); 6 file.after(file.clone().val("")); 7 file.remove(); 8 alert("文件上传大小不允许超过100M!你的文件大小为:" + Math.round(doc.files[0].size / 1024 / 1024 * 100) / 100 + "M"); 9 return false; 10 } 11 } 12 }