不畏困难是不是成语:求助一段JavaScript的错误纠正

来源:百度文库 编辑:高校问答 时间:2024/04/28 00:37:59
这段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+"。图像尺寸过大!您只能上传尺寸不超过 800×600的图像,请重新浏览图片!");
return true;
}else{
return false;
}
}else{
return true;
}
}

function detect(){
var ok=imgExceedSize(800,800);
if(ok){
document.IUpload.reset();
}else{
document.IUpload.submit();
}
}

//-->
</SCRIPT>

function imgExceedSize(w,h){
if(!document.IUpload.picsrc.value==""){
if(picshow.width>w||picshow.height>h){
alert("图像尺寸:"+picshow.width+"X"+picshow.height+"。图像尺寸过大!您只能上传尺寸不超过 800×600的图像,请重新浏览图片!");
return false; (这里是false,有提示了那就表示不提交)
}else{
return true; (这里是true,既然没提示就提交当然true)
}

else{
return true;;(这个else感觉没什么作用呀,你要它干吗?而且它应该是false才对,因为你前面判断值不为空时才判断他是否超重,既然为空拉,那你还提交????)

}
}

朋友,你这个不是无法提交吧?应该表单是可以提交的,但提交后,那边收不到数据。对吧?
如果我分析没错,那么你的情况,应该是在这句里。
我下面给你写上一句,你把这句,替换你原来的那句,再试,想必应该没问题了。
<form name="IUpload" action="upfile.asp" method="post" enctype="multipart/form-data">