所以我有一个自动生成的 div,里面有 3 个具有不同 id 和名称的复选框,默认情况下没有一个被选中!如果其中一个碰巧被检查,那么我需要另外两个未被检查!
所以一次只能检查一个......
所以全部未选中或仅选中一项!
<div class="configoptions">
<table class="configtable" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="fieldlabel">Include:</td>
<td class="fieldarea">
<label><input name="configoption[10]" id="co30" value="1" onclick="recalc()" type="checkbox">green</label>
</td>
</tr>
<tr>
<td class="fieldlabel">Include:</td>
<td class="fieldarea">
<label><input name="configoption[9]" id="co27" value="1" onclick="recalc()" type="checkbox">blue</label>
</td>
</tr>
<tr>
<td class="fieldlabel">Include:</td>
<td class="fieldarea">
<label><input name="configoption[11]" id="co31" value="1" onclick="recalc()" type="checkbox">white</label>
</td>
</tr>
</tbody>
</table>
</div>
这是我用来取消选中页面上所有 div 的方法..因为最初我需要取消选中它们..效果很好...现在我需要做到这一点,所以如果选中的话,一次只检查一个!有人可以帮忙吗?提前谢谢!
$(document).ready(function() {
$('input[type=checkbox]').each(function() {
this.checked = false;
});
});
最佳答案
使用prop
函数更改复选框和单选按钮的checked属性
$(function(){
$('input:checkbox').prop('checked', false)
$('input:checkbox').click(function(){
if($(this).is(':checked')){
$('input:checkbox').not(this).prop('checked', false);
}
});
})
演示:Fiddle
关于div 内的 Jquery 复选框一次选中一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15356300/