原文链接
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name="DEscription" contect="my code demo" />
<meta name="Author" contect="Michael@jb51.net" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE8">
<title>js check file size @ jb51.net</title>
< img id="tempimg" dynsrc="" src="" style="display:none" />
<input type="file" name="file" id="fileuploade" size="40" />
<input type="button" name ="check" value="checkfilesize" οnclick="checkfile()"/>
<script type="text/javascript">
var errMsg = "上传的附件文件不能超过2M!!!";
var tipMsg = "您的浏览器暂不支持计算上传文件的大小,确保上传文件不要超过2M,建议使用IE、FireFox、Chrome浏览器。";
var ua = window.navigator.userAgent;
if (ua.indexOf("MSIE")>=1){
}else if(ua.indexOf("Firefox")>=1){
browserCfg.firefox = true;
}else if(ua.indexOf("Chrome")>=1){
browserCfg.chrome = true;
var obj_file = document.getElementById("fileuploade");
if(browserCfg.firefox || browserCfg.chrome ){
filesize = obj_file.files[0].size;
var obj_img = document.getElementById(‘tempimg‘);
obj_img.dynsrc=obj_file.value;
filesize = obj_img.fileSize;
}else if(filesize>maxsize){
js判断文件大小利用img 的 dynsrc,兼容IE10 及以上
原文:https://www.cnblogs.com/sunny3158/p/12181852.html