[英]Checkbox behaviour modification with javascript
我有一组类似单选按钮的复选框。
在允许用户也允许取消选中复选框方面,我需要一些帮助,因此该组中不能有任何选择。
<label><input type="checkbox" name="cb1" class="chb" /> CheckBox1</label>
<label><input type="checkbox" name="cb2" class="chb" /> CheckBox2</label>
<label><input type="checkbox" name="cb3" class="chb" /> CheckBox3</label>
<label><input type="checkbox" name="cb4" class="chb" /> CheckBox4</label>
$(".chb").each(function()
{
$(this).change(function()
{
$(".chb").attr('checked',false);
$(this).attr('checked',true);
});
});
$(".chb").change(function()
{
$(".chb").parent().siblings()
.find('input').prop('checked', false);
});
甚至更好:
var $inputs = $(".chb");
$inputs.change(function()
{
$inputs.not(this).prop('checked', false);
});
这是小提琴: http : //jsfiddle.net/zjJKc/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.