如何在使用jquery检查其他对象时取消选中框 [英] how to I uncheck boxes when checking others with jquery
本文介绍了如何在使用jquery检查其他对象时取消选中框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个html -
I have this html -
<ol class="subproduct">
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test<span class="price"><span>+2</span>€</span></h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test</h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="15 min extra" />
<p class="checkbox"></p>
<h3>test/h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test</h3>
<p>test words</p>
</li>
</ol>
我需要添加一个类到li上'检查'复选框。目前我使用此
which I need to add a class to the li on 'checking' the checkbox. Currently I use this
$(document).ready(function() {
$('.subproduct input:checkbox').change(function(){
if($(this).is(":checked")) {
$(this).parent().toggleClass("checked");
}
});
});
但我需要它,所以只有一个复选框被用户选中,如果他们检查另一个框
but I need it so that only ever one checkbox is checked by the user so if they check another box it removes the class of any other
这是怎么回事?
推荐答案
请参阅: 示例
See this: Sample
$(document).ready(function() {
$('.subproduct input:checkbox').change(function(){
$('.subproduct input:checkbox').not(this).attr("checked",false);
$(".subproduct li").removeClass("checked");
if($(this).is(":checked")) {
$(this).parent().toggleClass("checked");
}
});
});
这篇关于如何在使用jquery检查其他对象时取消选中框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文