【问题标题】:How to uncheck radio button upon double clicking?双击后如何取消选中单选按钮?
【发布时间】:2014-05-11 22:53:33
【问题描述】:

我想要这个功能:

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

我正在尝试这段代码,但没有成功。

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

【问题讨论】:

标签: javascript jquery


【解决方案1】:

你可以试试

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

演示:Fiddle

【讨论】:

    【解决方案2】:

    您可以使用.dblclick()

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

    【讨论】:

      【解决方案3】:

      我是这样想的:

      $(document).on('dblclick','.yourCls',function(){
         if(this.checked){ // if true
            $(this).prop('checked', !this.checked); // then !this.checked == false
         }
      });
      

      您必须检查其检查状态this.checked 返回布尔值true/false。如果true 取消选中它,否则选中它。

      【讨论】:

        【解决方案4】:

        试试这个

        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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-01-31
          • 2012-06-08
          • 2011-06-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-06
          • 2011-01-08
          相关资源
          最近更新 更多