2011-02-01 101 views

回答

2

您可以使用:radio選擇器,並將其與:checked合併以獲取選中的無線電元件。

這應該爲你工作:

$("input[name=rmode]:radio:checked"); 

例如在jsfiddle

1

這應該返回這是目前檢查單選按鈕:

var id = $("input[@name=rmode]:checked").attr('id'); 

更多信息here。希望有所幫助!

+0

當然,如果你使用的是jQuery 1.2.6。它會打破更新的版本; o) – user113716 2011-02-01 17:13:57

2
... 
<input type="radio" name="sample" value="1" /> 
<input type="radio" name="sample" value="2" checked="checked" /> 
<input type="radio" name="sample" value="3" /> 
... 

//javascript code 

<script type="text/javascript"> 
<!-- 
    // displays the selected radio button in an alert box 
    alert($('input[name=sample]:checked').val()) 
--> 
</script> 
相關問題