循环判断单选是否选择了--可做为试题循环判断
html
<div class="form-group clearfix"> <label class="col-xs-12 l_name"><strong>*</strong>{$to.title}</label> <img class="col-xs-12" src="<?php echo C('IMG_URL'); ?>{$to.picture}" class="img-responsive" alt="Responsive image"> <div class="col-xs-12 panduan" style="margin:20px auto"> <label class="col-xs-3"><input name="shiti[{$k}][]" type="radio" value="A" />A </label> <label class="col-xs-3"><input name="shiti[{$k}][]" type="radio" value="B" />B </label> <label class="col-xs-3"><input name="shiti[{$k}][]" type="radio" value="C" />C </label> <label class="col-xs-3"><input name="shiti[{$k}][]" type="radio" value="D" />D </label> </div> </div> </foreach>
<div class="form" > <form class="yourform" action="/index.php?s=/Home/Zli/score" method="post" id='form1' enctype="multipart/form-data"> <input type="hidden" name="aid" value="2"> <!-- 填空题 --> <div class="form-group clearfix"> <label class="col-xs-12 l_name"><strong>*</strong>4. 请选择最适合的一项填入问号处,使之符合之前四个图形的变化规律。</label> <img class="col-xs-12" src="/Home/Public/images/weixin/shiti2_1.png" class="img-responsive" alt="Responsive image"> <div class="col-xs-12 panduan" style="margin:20px auto"> <label class="col-xs-3"><input name="shiti[0][]" type="radio" value="A" />A </label> <label class="col-xs-3"><input name="shiti[0][]" type="radio" value="B" />B </label> <label class="col-xs-3"><input name="shiti[0][]" type="radio" value="C" />C </label> <label class="col-xs-3"><input name="shiti[0][]" type="radio" value="D" />D </label> </div> </div><div class="form-group clearfix"> <label class="col-xs-12 l_name"><strong>*</strong>5. 从所给的四个选项中,选择最合适的一个填入问号处,使之呈现一定的规律性:</label> <img class="col-xs-12" src="/Home/Public/images/weixin/shiti2_2.png" class="img-responsive" alt="Responsive image"> <div class="col-xs-12 panduan" style="margin:20px auto"> <label class="col-xs-3"><input name="shiti[1][]" type="radio" value="A" />A </label> <label class="col-xs-3"><input name="shiti[1][]" type="radio" value="B" />B </label> <label class="col-xs-3"><input name="shiti[1][]" type="radio" value="C" />C </label> <label class="col-xs-3"><input name="shiti[1][]" type="radio" value="D" />D </label> </div> </div><div class="form-group clearfix"> <label class="col-xs-12 l_name"><strong>*</strong>6.从所给的四个选项中,选择最合适的一个填入问号处,使之呈现一定的规律性:</label> <img class="col-xs-12" src="/Home/Public/images/weixin/shiti2_3.png" class="img-responsive" alt="Responsive image"> <div class="col-xs-12 panduan" style="margin:20px auto"> <label class="col-xs-3"><input name="shiti[2][]" type="radio" value="A" />A </label> <label class="col-xs-3"><input name="shiti[2][]" type="radio" value="B" />B </label> <label class="col-xs-3"><input name="shiti[2][]" type="radio" value="C" />C </label> <label class="col-xs-3"><input name="shiti[2][]" type="radio" value="D" />D </label> </div> </div> <div class="clearfix"></div> <div class="text-center"> <button id="btnGo" type="button" onclick="return validateForm();" class="btn">提交</button> </div> </form> </div
jquery
<script type="text/javascript"> function validateForm(){ var tishi = true; $.each($(".panduan"),function(i,item){ if(!$(this).find("input:checked").size()){ tishi = false; } }); if(tishi){ $("#form1").submit(); }else{ alert("您未答题完毕,请完成后点击提交"); } } </script>