当前页面: 开发资料首页 → Javascript 专题 → 限制图片上传长宽的JavaScript代码
摘要: 限制图片上传长宽的JavaScript代码
代码如下:
<textarea class="bk" id="temp79230" onmouseover="this.select();" style="WIDTH: 90%" rows="12">
<head>
<input type="file" name="picsrc" size="40" onchange="picshow.src=document.IUpload.picsrc.value"> <input type="button" value="上载" onclick="detect()">
</form> </body> <script LANGUAGE="JavaScript"> function imgExceedSize(w,h){ if(!document.IUpload.picsrc.value==""){ if(picshow.width>w||picshow.height>h){ alert("图像尺寸:"+picshow.width+"X"+picshow.height+"。\\n图像尺寸过大!你只能上传尺寸为 "+w+"×"+h+"的图像,请重新浏览图片!"); return true; }else{ return false; } }else{ return true; } } function detect(){ var ok=imgExceedSize(50,50); if(ok){ document.IUpload.reset(); }else{ document.IUpload.submit(); } } // </script></textarea>