jquery checkbox实现单选小例

来源:互联网 发布:网络招聘怎么做 编辑:程序博客网 时间:2024/05/16 15:56
checkbox是复选框如何将其变为单选呢?下面有个不错的示例,感兴趣的朋友可以参考下
复制代码代码如下:

$(function(){ 
$(':checkbox[name=flag]').each(function(){ 
$(this).click(function(){ 
if($(this).attr('checked')){ 
$(':checkbox[name=flag]').removeAttr('checked'); 
$(this).attr('checked','checked'); 

}); 
}); 

}); 

<input name="flag" id="agree" type="checkbox" checked="checked" value="0"/> 同意 
<input name="flag" id="reject" type="checkbox" value="1" /> 不同意 

0 0
原创粉丝点击