三个Checkbox,一个必须选择启用提交按钮,需要Jquery?(Three Checkboxes, One must be selected to enable submit button, ne

编程入门 行业动态 更新时间:2024-10-23 17:32:49
三个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'); } }); });​

更多推荐

本文发布于:2023-07-30 23:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   Checkboxes   Jquery   Checkbox   submit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!