複選框不能為空的校驗
阿新 • • 發佈:2019-02-08
<td> <input type="checkbox" class="product1" name="product" value="SCAN" <c:forEach var="merproduct" items="${merchant.product}"> <c:if test="${merproduct=='SCAN'}"> checked="checked"</c:if> </c:forEach> >掃碼通道 <input type="checkbox" class="product1" name="product" value="POS" <c:forEach var="merproduct" items="${merchant.product}"> <c:if test="${merproduct=='POS'}"> checked="checked"</c:if> </c:forEach> >POS通道 </td>
if($(".product1:checked").length==0){
alert("通道型別不能為空")
return;
}
注意:選擇器冒號前面不能有空格,否則會涉及到從所有標籤裡面找,而不是從 .product1 篩選後中的找