如何在双击时取消选中单选按钮?

时间:2014-04-01 09:03:15

标签: javascript jquery

我想要这个功能:

当用户点击已经选中的单选按钮时,应该取消选中它。

我正在尝试这段代码,但没有运气。

$(document).on('mouseup','className',function(){
    if ($(this).is(':checked')){
        $(this).prop('checked', false);
    }
});

4 个答案:

答案 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取消选中它,或者检查它。