jquery checkbox实现单选小例
(编辑:jimmy 日期: 2025/5/12 浏览:3 次 )
复制代码 代码如下:
$(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" /> 不同意
$(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" /> 不同意
下一篇:子页向父页传值示例