根据class 属性判断所有的文本框必填
<body> <!-- 遮罩层 --> <div id="hidediv" style="width: 100%;height: 100%;background-color: #808080;z-index: 99999;display: none;opacity:0.5;position: absolute;"></div> <div id="main_login"> <s:include value="../../top.jsp"> <s:param name="menuTitle">兼职人员工资结算方式-编辑</s:param> </s:include> <div class="content_login"> <div class="line_bottom padding_style1"> <a href="javascript:history.back(-1)"><i class="icon-backward"></i> 返回</a> </div> <s:form id="form" action="%{#request['struts.actionMapping'].name}" theme="bootstrap" cssClass="form-horizontal m_top col-md-8"> <s:hidden name="id"></s:hidden> <input type="hidden" id="ceoId" name="ceoId" value="${ceo }"/> <input type="hidden" id="riderId" name="riderId" value="${rider }"> <input type="hidden" id="type" name="type" value="${ceoCommissionType }"> <!-- 工资结算方式(骑手/楼长) --> <c:if test="${rider eq 1 }"> <div class="control-group form-group"> <label for="工资结算方式" class="col-md-2 control-label">工资结算方式(骑手/楼长)</label> <div class="col-md-9 checkbox checkbox-inline"> <label class="radio-inline"><input type="radio" name="commissionType" <s:if test="commissionType == 1">checked="checked"</s:if> value="1" onclick="riderChoose('1')"/>配送费分成</label> <label class="radio-inline"><input type="radio" name="commissionType" <s:if test="commissionType == 2">checked="checked"</s:if> value="2" onclick="riderChoose('2')"/>营业额百分比分成</label> <label class="radio-inline"><input type="radio" name="commissionType" <s:if test="commissionType == 3">checked="checked"</s:if> value="3" onclick="riderChoose('3')"/>配送费+营业额百分比分成</label> </div> </div> <div class="control-group form-group" id="distributionId" style="display: none;"> <label class="col-md-2 control-label">配送费分成(单位:%)</label> <div class="col-md-9"> <input type="text" name="distributionPercent" value="${distributionPercent}" class="form-control" style="width: 100px"/> <span class="help-block"><span class="label"></span></span> <div class="controls"></div> </div> </div> <div class="control-group form-group" id="stallsuctionId" style="display:none;"> <label class="col-md-2 control-label">营业额百分比分成(单位:%)</label> <div class="col-md-9"> <c:choose> <c:when test="${!empty riderList }"> <c:forEach items="${riderList }" var="rider" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_rider_percent"> <input type="text" id="riderSettlementList[${num}].percent" name="riderSettlementList[${num}].percent" value="${rider.percent}" class="form-control stall_percent" style="width: 100px"/>${rider.stallName } <input type="hidden" id="riderSettlementList[${num}].stallId" name="riderSettlementList[${num}].stallId" value="${rider.stallId }"> </div> </c:forEach> </c:when> <c:otherwise> <c:forEach items="${stallList }" var="stall" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_rider_percent"> <input type="text" id="riderSettlementList[${num}].percent" name="riderSettlementList[${num}].percent" value="" class="form-control stall_percent" style="width: 100px"/>${stall.name } <input type="hidden" id="riderSettlementList[${num}].stallId" name="riderSettlementList[${num}].stallId" value="${stall.id }"> </div> </c:forEach> </c:otherwise> </c:choose> </div> </div> </c:if> <!-- 工资结算方式(校园CEO) ceo抽佣方式:1:档口营业额分成,2:档口订单分成--> <c:if test="${ceo eq 2 }"> <div class="control-group form-group"> <label for="工资结算方式" class="col-md-2 control-label">工资结算方式(校园CEO)</label> <div class="col-md-9 checkbox checkbox-inline"> <label class="radio-inline"><input type="radio" name="ceoCommissionType" <s:if test="ceoCommissionType == 1">checked="checked"</s:if> value="1" onclick="ceoChoose('1')"/>营业额百分比分成</label> <label class="radio-inline"><input type="radio" name="ceoCommissionType" <s:if test="ceoCommissionType == 2">checked="checked"</s:if> value="2" onclick="ceoChoose('2')"/>营业额订单固定分成</label> </div> </div> <div class="control-group form-group" id="dividedIntoId" style="display: none;"> <label class="col-md-2 control-label">营业额订单固定分成(单位:元)</label> <div class="col-md-9"> <c:choose> <c:when test="${!empty ceoList }"> <c:forEach items="${ceoList }" var="ceo" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_ceo_money"> <input type="text" id="ceoOrderSettlementList[${num}].money" name="ceoOrderSettlementList[${num}].money" value="${ceo.money}" class="form-control stall_money" style="width: 100px"/>${ceo.stallName } <input type="hidden" id="ceoOrderSettlementList[${num}].stallId" name="ceoOrderSettlementList[${num}].stallId" value="${ceo.stallId }"> </div> </c:forEach> </c:when> <c:otherwise> <c:forEach items="${stallList }" var="stall" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_ceo_money"> <input type="text" id="ceoOrderSettlementList[${num}].money" name="ceoOrderSettlementList[${num}].money" value="" class="form-control stall_money" style="width: 100px"/>${stall.name } <input type="hidden" id="ceoOrderSettlementList[${num}].stallId" name="ceoOrderSettlementList[${num}].stallId" value="${stall.id }"> </div> </c:forEach> </c:otherwise> </c:choose> </div> </div> <div class="control-group form-group" id="turnoverId" style="display: none;"> <label class="col-md-2 control-label">营业额百分比分成(单位:%)</label> <div class="col-md-9"> <c:choose> <c:when test="${!empty ceoList }"> <c:forEach items="${ceoList }" var="ceo" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_ceo_percent"> <input type="text" id="ceoSettlementList[${num}].percent" name="ceoSettlementList[${num}].percent" value="${ceo.percent}" class="form-control stall_percent" style="width: 100px"/>${ceo.stallName } <input type="hidden" id="ceoSettlementList[${num}].stallId" name="ceoSettlementList[${num}].stallId" value="${ceo.stallId }"/> </div> </c:forEach> </c:when> <c:otherwise> <c:forEach items="${stallList }" var="stall" begin="0" varStatus="status"> <c:set value="${status.count-1 }" var="num"></c:set> <div class="stall_money_ceo_percent"> <input type="text" id="ceoSettlementList[${num}].percent" name="ceoSettlementList[${num}].percent" value="" class="form-control stall_percent" style="width: 100px"/>${stall.name } <input type="hidden" id="ceoSettlementList[${num}].stallId" name="ceoSettlementList[${num}].stallId" value="${stall.id }"/> </div> </c:forEach> </c:otherwise> </c:choose> </div> </div> </c:if> <div class="col-md-offset-2"> <a id="subUpdate" class="btn btn-default" style="margin-left: 80px;">保存</a> </div> </s:form> </div> </body>
js
var type = $('input[name="type"]').val(); //骑手楼长营业额百分比分成 var flag = false; $(".stall_money_rider_percent").each(function(){ var value = $(this).find(".stall_percent").val(); if(value==null || value==""){ flag=true; return false; } }); if(flag){ alert('骑手楼长营业额百分比分成必填'); return; } //ceo营业额百分比分成 if(type==1){ $(".stall_money_ceo_percent").each(function(){ var value = $(this).find(".stall_percent").val(); if(value==null || value==""){ flag=true; return false; } }) if(flag){ alert('ceo营业额百分比分成必填') return; } } //ceo营业额订单固定分成必填 if(type==2){ $(".stall_money_ceo_money").each(function(){ var value = $(this).find(".stall_money").val(); if(value==null || value==""){ flag = true; return false; } }); if(flag){ alert('ceo营业额订单固定分成必填'); return; } }