file control

看来你是想验证是否为空,不是要检测大小 

<form name="fr" action="up.asp" method="post" enctype="multipart/form-data" onsubmit="return chk()"> 
<input type="file" name="file" size="30"> 
<input type="submit" name="submit" value="上传"> 
<script language="javascript"> 
function chk() 

var s
=fr.file.value; 
if(fr.file.value==""

alert(
"请输入图片地址!"); 
fr.file.focus(); 
return false

s
=s.substr(s.lastIndexOf(".")+1,3); 
if(s!="gif"&&s!="jpg"

alert(
"请选择正确的图片格式!"
return false


</script> 
--------------------------------------------------------------------
<input   id=inp   type="file">   
  
<button   onclick="ys()">Test</button>   
  
<script>   
  var   img
=null;   
  function   ys()   
  {   
  
if(img)img.removeNode(true);   
  img
=document.createElement("img");   
  img.style.position
="absolute";   
  img.style.visibility
="hidden";   
  img.attachEvent(
"onreadystatechange",orsc);   
  img.attachEvent(
"onerror",oe);   
  document.body.insertAdjacentElement(
"beforeend",img);   
  img.src
=inp.value;   
  }   
  function   oe()   
  {   
  alert(
"cant   load   img");   
  }   
  function   orsc()   
  {   
  
if(img.readyState!="complete")return   false;   
  alert(
"图片大小:"+img.offsetWidth+"X"+img.offsetHeight);   
  alert(
"图片尺寸:"+img.fileSize);   
  }   
  
</script>
------------------------------------------------------------------------------------
<input   name="file1"   type="file"   class="style1"     size="18"   onpropertychange="document.all.testImage1.src=this.value">   
                      
<font   size="2"></font>     
                      
<input   name="ow1"   type="text"   class="style1"   id="ow1"   style="background-color:#efefef;"   size="3"     readonly>   
                      
<font   size="2">px   高</font>     
                      
<input   name="oh1"   type="text"   class="style1"   id="oh1"   style="background-color:#efefef;"   size="3"     readonly>   
                      
<SCRIPT   LANGUAGE="JavaScript">   
  
<!--   
  var   upStr
="<INPUT     TYPE=\"file\"   NAME=\"file1\"   onpropertychange=\"document.all.testImage1.src=this.value\"   >";   
  
//-->   
  </SCRIPT>   
                  
<input   name=testit1   type=hidden   value="">   
                  
<div   id="Layer1"   style="position:absolute;   left:232px;   top:204px;   55px;   height:49px;   z-index:1">     
                      
<img   src="syspic/upset0.gif"   name=testImage1   
  onload
="   
  {   
  var   objs
=document.all   
  
if   (objs.testit1.value!='')   
  {   
  objs.ow1.value
=this.width;   
  objs.oh1.value
=this.height;   
  }   
  
else   
  {   
  objs.testit1.value
=1;   
  }   
  }
"   
  onerror="{alert('选择的图像类型错误或者目标不存在');window.upfile.innerHTML=upStr;}"     
  
></div>
原文地址:https://www.cnblogs.com/hq2008/p/849419.html