1:单选框,直接定位到属性名称
$(document).ready(function(){ var old = null; //用来保存原来的对象 $("input[name='sex']").each(function(){//循环绑定事件 if(this.checked){ this.checked= false; }else{ this.checked = true; } }); });
2.根据iD
function select_input(hid){ jQuery("#"+hid).each(function(){//循环绑定事件 if(this.checked){ this.checked = false; }else{ this.checked = true; } }); }
本文介绍了一种使用JavaScript操作单选按钮的方法,通过遍历并改变其checked属性实现单选框状态的反转。适用于网页表单中快速切换选项的需求。
1354

被折叠的 条评论
为什么被折叠?



