`

js判断上传文件大小

阅读更多
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">

	<SCRIPT LANGUAGE="JavaScript">
		function doupload(){
			var imgsrc = document.getElementById("thefile").value;
			var theimg = document.getElementById("theimg");
			var thebnt = document.getElementById("thebnt");
 
			theimg.src = imgsrc;


			theimg.onload = function(){
				if(theimg.fileSize > 300*1024){
					thebnt.style.display = "none";
					alert("图片不能大于300K!");
				}else {
					thebnt.style.display = "";
				}
			}


			theimg.onerror = function(){
				thebnt.style.display = "none";
				alert("上传图片有误,请更换图片!");
			}
		}
 
	</SCRIPT>
   
       

 </HEAD>

 <BODY>
  
   <input type="file" id="thefile" onchange="doupload()"/>
   <input type="button" value="上传" id="thebnt" onclick="doupload()" style="display:none;"  />
   <img src="" id="theimg" style="display:none;" >
 </BODY>
</HTML>

 

2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics