我想要这个功能:
当用户点击已经选中的单选按钮时,应该取消选中它。
我正在尝试这段代码,但没有运气。
$(document).on('mouseup','className',function(){
if ($(this).is(':checked')){
$(this).prop('checked', false);
}
});
答案 0 :(得分:6)
你可以尝试
$(document).on('dblclick','.className',function(){
if(this.checked){
$(this).prop('checked', false);
}
});
演示:Fiddle
答案 1 :(得分:1)
试试这个
<强> HTML 强>
<input type="radio" class="rdCheck" checked="checked" text="click me"/> click me
<强> JS 强>
$('.rdCheck').dblclick(function(){
if($(this).is(':checked'))
{
$(this).removeAttr('checked');
}
});
<强> DEMO HERE 强>
答案 2 :(得分:0)
您可以使用 .dblclick() :
$(document).on('dblclick','className',function(){
if ($(this).is(':checked')){
$(this).prop('checked', false);
}
});
答案 3 :(得分:0)
我想是这样的:
$(document).on('dblclick','.yourCls',function(){
if(this.checked){ // if true
$(this).prop('checked', !this.checked); // then !this.checked == false
}
});
您必须检查其已检查状态this.checked
是否返回布尔值true/false
。如果true
取消选中它,或者检查它。