三个Checkbox,一个必须选择启用提交按钮,需要Jquery?(Three Checkboxes, One must be selected to enable submit button, needs Jquery?)
我有1到3个复选框,默认情况下它们都被禁用。 为了使提交按钮处于活动状态,必须选择最小复选框。 有人可以帮助我使用jquery片段来实现这一目标吗? 我的标记看起来像这样,网站使用jquery 1.42。 谢谢,麻烦您了!
<form action="/cart/add" method="post" id="pform"> <h3 class="goudy">Make your selection:</h3> <ul id="variants"> <li> <input type="checkbox" name="id[]" value="39601622" id="radio_39601622" style="vertical-align: middle;" class="required" /> <label for="radio_39601622[]">$38.00 - Original Antique Photo</label> </li> <li> <input type="checkbox" name="id[]" value="39601632" id="radio_39601632" style="vertical-align: middle;" class="required" /> <label for="radio_39601632[]">$8.99 - SCAN</label> </li> <li> <input type="checkbox" name="id" value="39777962" id="radio_39777962" style="vertical-align: middle;" class="required" /> <label for="radio_39777962">$2.99 - Rigid Sleeve</label> </li> </ul> <div class="buttons clearfix"> <input type="image" src="../images/add-to-cart.png" name="add" value="Add to Cart" id="add" class="send-to-cart" /> </div> </form>I have between 1-three checkboxes and by default they are all disabled. In order for the submit button to be active ove checkbox minumum must be selected. Can someone help me with a jquery snippet to achieve this? My markup looks like this and the site used jquery 1.42. Please and thankyou!
<form action="/cart/add" method="post" id="pform"> <h3 class="goudy">Make your selection:</h3> <ul id="variants"> <li> <input type="checkbox" name="id[]" value="39601622" id="radio_39601622" style="vertical-align: middle;" class="required" /> <label for="radio_39601622[]">$38.00 - Original Antique Photo</label> </li> <li> <input type="checkbox" name="id[]" value="39601632" id="radio_39601632" style="vertical-align: middle;" class="required" /> <label for="radio_39601632[]">$8.99 - SCAN</label> </li> <li> <input type="checkbox" name="id" value="39777962" id="radio_39777962" style="vertical-align: middle;" class="required" /> <label for="radio_39777962">$2.99 - Rigid Sleeve</label> </li> </ul> <div class="buttons clearfix"> <input type="image" src="../images/add-to-cart.png" name="add" value="Add to Cart" id="add" class="send-to-cart" /> </div> </form>最满意答案
禁用表单按钮的另一种方法,如果没有选中!
$(function() { $('#add').attr('disabled','disabled'); $('#pform input:checkbox').bind('click',function() { if($(this).is(':checked')) { $('#add').removeAttr('disabled'); } else { $('#add').attr('disabled','disabled'); } }); });Another way with disabled form button if nothing checked!
$(function() { $('#add').attr('disabled','disabled'); $('#pform input:checkbox').bind('click',function() { if($(this).is(':checked')) { $('#add').removeAttr('disabled'); } else { $('#add').attr('disabled','disabled'); } }); });更多推荐
发布评论