[英]How to check radio button with radio button value
我有值為YES和NO的單選按鈕
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="YES" onclick="IS_INCOMEPROOF_VERFIED1()"/>
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()"/>
如何使用單選按鈕值選擇單選框。例如,我希望選擇單選按鈕的NO值。它應該像這樣
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()" cheked="checked"/>
嘗試這個:
$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked', true);
工作提琴: http : //jsfiddle.net/qKEgL/
嘗試這個
$("input[name='IS_INCOMEPROOF_VERFIED']").each(function(){
if($(this).val() === 'NO') {
$(this).attr('checked','checked');
}
});
只是用這個
$("[name=IS_INCOMEPROOF_VERFIED][value=NO]").attr("checked", true);
嘗試這個:
$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked','checked')
你為什么不給它id並選擇它
<input id"rdNo" type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()"/>
$("#rdNo")...;
選擇值為NO
(假設需要名稱)的單選按鈕的jQuery選擇器將是:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']")
要對其進行檢查(使用jQuery 1.6+),可以使用:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']").prop("checked", true);
要對其進行檢查(使用<jQuery 1.6),可以使用:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked', 'checked');
這是一個有效的jsFiddle示例。
為了使代碼更整潔並便於選擇,建議為所有input
元素賦予唯一的ID。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.