高手们!问题来了,还是有关图片上传时的客户端判断的问题,马上给分。
下面是我的源代码。
我想一下子上传多个图片,然后分别判断图片的合法性。
但是问题来了,一两个文件的时候还可以。多了就不行。
好像是循环到第三个文件域的时候就过不去了。但是拿光标点一下
其中任何一个文件域就又可以了。靠,真是变态。
是不是有办法让程序慢慢的一个一个的判断?
哪位能解决,马上给分并致谢,最好讲出道理来,我想了一下午想不明白。
书崩溃了。:(
源代码:
复制另存为.htm就可以。谢谢了。。
<html>
<head>
<title>我的图片上传检测</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<link rel="stylesheet" href="../Common/Css/Comon.css" type="text/css">
</head>
<body bgcolor="#ffffff" text="#000000" leftmargin="0" topmargin="0" onLoad="MM_preloadImages('../images/mainf2.gif')">
<table width="778" align="center" height="420">
<tr bgcolor="#FFFFFF">
<td align="center" valign="top">
<form method="POST" name="frmManage" enctype="multipart/form-data" action="ContentSave.asp?CodeID=020101&CSS=1235" onSubmit="return check()">
<input type="hidden" name="userName" value="zhoutao">
<input type="hidden" name="CSS" value="1235">
<input type="hidden" name="CodeID" value="020101">
<input type="hidden" name="selectBodyColor" value="">
<input type="hidden" name="selectFontColor" value="">
<input type="hidden" name="selectFontSize" value="">
<table width="778" border="1" cellspacing="1" cellpadding="1" bgcolor="#003366" bordercolor="#FFFFFF">
<tr bgcolor="#003366" align="center">
<td colspan="3" height="25"><font size="3" color="#FFFFFF"><b>内容录入</b></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%" align="right"><b>标题</b>:</td>
<td colspan="2"> <input type="text" name="txtTitle" size="50" maxlength="100" class="inte">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%" align="right"><strong>关键字</strong> :</td>
<td colspan="2"><input name="tfkey" type="text" id="tfkey" size="20" maxlength="20" class="inte">
<font color="#FF0000">(请输入标题关键字,以利于新闻搜索功能!)</font></td>
</tr>
<tr valign="bottom" bgcolor="#FFFFFF">
<td colspan="2" height="20"><b>请填写内容部分</b>:</td>
<td height="20" width="39%"><b>更改人</b>: 就是大哥你了。:)</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="3">
<table align=center><tr><td>第 <font color=#ff0000>1</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file1' class=inte title=1><br><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo1' class=inte></td><td width='50%' height=100 align=center><BR><font color=#0000FF>请录入文章内容:</font><BR><TEXTAREA rows=6 cols=55 name='txtContent1' class=inte></TEXTAREA><BR><BR></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>2</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><BR><font color=#0000FF>请录入文章内容:</font><BR><TEXTAREA rows=6 cols=55 name='txtContent2' class=inte></TEXTAREA><BR><BR></td><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file2' class=inte title=1><br><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo2' class=inte><input type=hidden name='hidDir2' value=''></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>3</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file3' class=inte title=1><br><input type=hidden name='hidDir3' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo3' class=inte></td><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file13' class=inte title=1><br><input type=hidden name='hidDir13' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo13' class=inte></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>4</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='100%' align=center height=100><font color=#0000FF>请选择图片文件:</font><input type=file name='file4' class=inte title=1><br><input type=hidden name='hidDir4' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo4' class=inte></td></tr></Table> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="3"> <div align="center">
<input type="submit" name="Submit" value=" 保 存 ">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
<script language="javascript">
<!--
//save The content To Data Page.
function check()
{
var lenVar;
var tout;
window.clearTimeout(tout);
lenVar=document.frmManage.txtTitle.value
if (document.frmManage.txtTitle.value=="")
{
alert("标题不能为空!")
document.frmManage.txtTitle.focus();
document.frmManage.Submit.disabled=false;
return false;
}
if (lenVar.length>100)
{
alert("对不起!您的标题过长,请不要超过50个汉字");
document.frmManage.Submit.disabled=false;
return false;
}
for(i=0;i<document.frmManage.elements.length;i++)
{
if (document.frmManage.elements[i].type=="file")
{
//document.frmManage.elements[i].focus();
if (document.frmManage.elements[i].value=="")
{alert('请选择您要上传的图片!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;
}
document.frmManage.Submit.disabled=true;
var img=new Image();
var imagewidth,imageheigth,fsize,myoffset,okoffset;
img.src=document.frmManage.elements[i].value;
if(document.frmManage.elements[i].title=='1')
okoffset=1.33;
if(document.frmManage.elements[i].title=='2')
okoffset=0.75;
if(img.readyState!="complete")
{
tout=window.setTimeout("check()",50);
return false;
//return false;
}
else
{
imagewidth=img.width;
imageheigth=img.height;
myoffset=imagewidth/imageheigth
myoffset=myoffset.toFixed(2);
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
if (myoffset>okoffset+0.1 || myoffset<okoffset-0.1)
{alert('上传的图片长宽比例不合法,请修改后重试!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;}
if(fsize>300)
{alert('上传的图片大小超出限制,最大为300KB!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;}
}
}
}
//document.frmManage.Submit.disabled=false;
return true;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>