复选框验证必填项

分享 未结 1 191
yuanyuanyuan
悬赏:20飞吻

验证复选框为必填项,html代码如下:
<div th:if="${(tab+'') ne '1'}" class="layui-form-item" pane="">
<label class="layui-form-label"><span class="xuan">*</span>项目类型</label>
<div class="layui-input-block" lay-verify="projectcheck" id="projectType">
<input type="checkbox" name="ispz" lay-skin="primary" title="普宅" th:checked="${project.ispz eq '1'}">
<input type="checkbox" name="isyf" lay-skin="primary" title="洋房" th:checked="${project.isyf eq '1'}">
<input type="checkbox" name="issy" lay-skin="primary" title="商业" th:checked="${project.issy eq '1'}" >
<input type="checkbox" name="isgy" lay-skin="primary" title="公寓" th:checked="${project.isgy eq '1'}">
<input type="checkbox" name="isbs" lay-skin="primary" title="别墅" th:checked="${project.isbs eq '1'}">
<input type="checkbox" name="isxzj" lay-skin="primary" title="写字间" th:checked="${project.isxzj eq '1'}">
</div>
</div>
js代码如下:
form.verify({
projectcheck: function (value, item) {
var lxItem="";
$("#projectType input[type='checkbox']").each(function(){
if($(this).prop("checked")){
lxItem = lxItem+","+$(this).val();
}
})
if (lxItem==""){return "请选择项目类型";}},
});
回帖