批量校验input 必填项不为空,代码如下:
一、前端页面js:
//批量校验input必填项
function check(){
var item = $("input[mustwrite='true']", document.forms[0]);
for( var i=0; i<item.length; i++ ){
if( item[i].value == "" ){
alert(item[i].title + " 为必填项");
item[i].focus(); //光标定位到未填input框中
return false;
}
}
return true;
}
二、前端页面html:
<div class="tab2-cont">
<div class="title">项目名称:</div>
<div class="cont text">
<input type="text" id="projectName" name="projectName" mustwrite="true" title="项目名称" value="${projectName}" required="required"/>
</div>
</div>
<div class="tab2-cont">
<div class="title">安装证书密码:</div>
<div class="cont text">
<input type="text" id="cerPwd" name="cerPwd" mustwrite="true" title="安装证书密码" value="${cerPwd}" required="required"/>
</div>
</div>
<div class="tab2-cont">
<div class="title">项目BundleId:</div>
<div class="cont text">
<input type="text" id="bundleId" name="bundleId" mustwrite="true" title="项目BundleIdentifier" value="${bundleId}" required="required"/>
</div>
</div>
<div class="tab2-cont">
<div class="title">描述文件:</div>
<div class="cont">
<input type="file" name="mobileProvision" mustwrite="true" title="描述文件" id="mobileProvision" />
</div>
</div>
<div class="tab2-cont">
<div class="title">证书:</div>
<div class="cont">
<input type="file" name="identityFile" mustwrite="true" title="证书" id="identityFile" />
</div>
</div>
三、注意:
1、input标签上要加上mustwrite="true"
2、input标签上要加上title="你想显示的内容"