2010-08-06 32 views
0

我有有一個包含的項目數jQuery的單選按鈕,新手的問題

<input type="radio" id="rb169"> 
<input type="radio" id="rb170"> 
<input type="radio" id="rb171"> 

如何使用jQuery來遍歷所有以「RB」開頭的所有單選按鈕的ID值單選按鈕的表確定選擇哪個#號碼?

我有類似:

return_type = $("input:radio["@name=rb*"]:checked").val(); 
if (return_type == undefined) { 
    alert("you did not select a radio button"); 
} 

但是,這並不工作,我選擇的方式。這是正確的嗎?

回答

0

$('input:radio[name^=rb]:checked').val()應該這樣做。您不再需要@,也不需要額外的引號。

0
return_type = $("input:radio["@name^=rb"]:checked").val(); 

這應該工作。開始是^ =

編輯:我注意到你的代碼在其他地方也是錯誤的。我在看的東西太狹窄了。這是更新:

return_type = $("input:radio[name^='rb']:checked").val();