这种情况下该如何验证?

shuaiwang_01 shuaiwang_01 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

<logic:notEmpty name="adminInfoForm" property="notVerifiedProductionList">
<logic:iterate id="production" name="adminInfoForm" property="notVerifiedProductionList" indexId="index">
<bean:write name="production" property="title"/>
<bean:write name="production" property="authors"/>
<bean:write name="production" property="time" format="yyyy-MM-dd"/>
<bean:write name="production" property="place"/>
<html:form action="/adminInfo" method="post" enctype="multipart/form-data" onsubmit="javascript:return check();">
<html:hidden property="method" value="uploadFile"/>
<input type="hidden" name="productionId" value="<bean:write name='production' property='id'/>"/>
上传文件:<html:file property="myFile"></html:file>
<input type="submit" value="上传"/>
</html:form>
</logic:iterate>
</logic:notEmpty>

在这个<html:form/>里面有个<html:file/>为了验证必须上传pdf文件,我写了下面一段Javascript

function check(){
var len = document.all.myFile.value.length;
var str = document.all.myFile.value;
var xx = str.substr(str.lastIndexOf("."),len);
if(xx == ".pdf"){
return true;
}
else{
alert("必须上传PDF格式文件");
return false ;
}
}


由于JSP页面中有logic:iterate,它会列出需要上传文件的所有框框,因而会有好多个<html:file property="myFile"/>,因而上面的JS验证就不能生效了,因为有好多个myFile,名字都一样,我想问的是该如何验证myFile必须为pdf格式?

(这里不能采纳多个同时上传的方法,因为每个pdf文件对应相对应的对象)
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
shuaiwang_01
Web 开发 81,107 成员 341,720 内容