2014-04-01 54 views
4

我想要这个功能:如何在双击时取消选中单选按钮?

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

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

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

复制? http://stackoverflow.com/questions/2117538/jquery-how-to-uncheck-a-radio-button – Eddie

回答

6

您可以尝试

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

演示:Fiddle

0

您可以使用.dblclick()

$(document).on('dblclick','className',function(){ 
    if ($(this).is(':checked')){ 
     $(this).prop('checked', false); 
    } 
}); 
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取消选中它或检查它。

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

相关问题