我想要這個功能:如何在雙擊時取消選中單選按鈕?
當用戶點擊已經選中的單選按鈕時,它應該取消選中它。
我正在嘗試此代碼,但沒有運氣。
$(document).on('mouseup','className',function(){
if ($(this).is(':checked')){
$(this).prop('checked', false);
}
});
我想要這個功能:如何在雙擊時取消選中單選按鈕?
當用戶點擊已經選中的單選按鈕時,它應該取消選中它。
我正在嘗試此代碼,但沒有運氣。
$(document).on('mouseup','className',function(){
if ($(this).is(':checked')){
$(this).prop('checked', false);
}
});
您可以嘗試
$(document).on('dblclick','.className',function(){
if(this.checked){
$(this).prop('checked', false);
}
});
演示:Fiddle
您可以使用.dblclick():
$(document).on('dblclick','className',function(){
if ($(this).is(':checked')){
$(this).prop('checked', false);
}
});
我想是這樣的:
$(document).on('dblclick','.yourCls',function(){
if(this.checked){ // if true
$(this).prop('checked', !this.checked); // then !this.checked == false
}
});
那麼你必須檢查它的選中狀態this.checked
返回布爾值true/false
。如果true
取消選中它或檢查它。
嘗試這個
HTML
<input type="radio" class="rdCheck" checked="checked" text="click me"/> click me
JS
$('.rdCheck').dblclick(function(){
if($(this).is(':checked'))
{
$(this).removeAttr('checked');
}
});
複製? http://stackoverflow.com/questions/2117538/jquery-how-to-uncheck-a-radio-button – Eddie