设计学院-ui163 致力于网页标准 网页设计 web标准与ui设计。

限制图片上传长宽的JavaScript代码

上一篇上一篇 | 下一篇下一篇发表时间:2007-11-3 14:28:07

限制图片上传长宽的JavaScript代码

以下代码片段:

  <html>
<head>
<title>Upload Image</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="IUpload" action="upfile.asp" method="post">
<p><input type="file" name="picsrc" size="40" onchange="picshow.src=document.IUpload.picsrc.value">
<input type="button" value="上载" onclick="detect()"></p></form>
<p><img name="picshow" src="http://51js.1000box.net/pics/face/19.gif" title="图像预览"></p>
</body>
</html>

<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>
[本日志由 ui163 于 2007-11-3 14:28:07 编辑]
上一篇上一篇:关于DOM事件模型的两件事
下一篇下一篇:JavaScript极速狂飙:CSS样式表的渲染效率
文章来自:设计学院
收藏到网摘: 收藏到QQ书签
Tags:

相关内容

网站建设导航→

相关内容

版权隐私 ┊ 免责声明  ┊ 友情链接 ┊ 网站地图  ┊ 联系我们

Copyrights©2006 UI163.com All Rights Reserved 2007

 豫ICP备07501346号