< Title > </ Title > < Script SRC = "JS/jquery-1.7.2.min.js" > </ Script > < Script Type = "Text/JavaScript" > $ ( Function (){ // No selected by default // First, judge whether radio has selected items and then obtain the selected values. $ ( " # Btnclick " ). Click ( Function (){ // Obtains the Value Attribute of the selected item. VaR Chkradio = $ ( ' Input: Radio [name = "list"]: checked ' ). Val (); If (Chkradio = Null ) {Alert ( " No selected items " ); Return False ;} Else {Alert (chkradio );}}); // Selected by default // Obtains the value of a selected item. Generally, the Traversal method is used to determine which item is selected and obtain the value of its value attribute. $ ( " # Btnclick2 " ). Click ( Function (){ VaR CHK2 = Getradiovalue ( " List2 " ); Alert (CHK2 );}); Function Getradiovalue (radioname ){ VaR Chkradio = Document. getelementsbyname (radioname ); For ( VaR I = 0 ; I < Chkradio. length; I ++ ){ If (Chkradio [I]. Checked) Return Chkradio [I]. Value ;}}}) </ Script > </ Head > < Body > < Div > < Input Type = "Radio" Name = "List" Value = "Very satisfied" /> Very satisfied < Input Type = "Radio" Name = "List" Value = "Satisfied" /> Satisfied < Input Type = "Radio" Name = "List" Value = "Not satisfied" /> Unsatisfied < Input Type = "Radio" Name = "List" Value = "Very poor" /> Very poor </ Div > < BR /> < Div > < Input Type = "Radio" Name = "List2" Value = "Very satisfied 2" Checked = "Checked" /> Very satisfied 2 < Input Type = "Radio" Name = "List2" Value = "Satisfied 2" /> Satisfied 2 < Input Type = "Radio" Name = "List2" Value = "Not satisfied 2" /> Unsatisfied 2 < Input Type = "Radio" Name = "List2" Value = "Very bad 2" /> Very bad 2 </ Div > < Input Type = "Button" Value = "OK" ID = "Btnclick" /> < Input Type = "Button" Value = "OK 2" ID = "Btnclick2" /> </ Body > </ Html >
Demo:
1. If no default item is selected, the result is null:
2. If no selected item is selected by default, obtain the value of the selected item:
3. If a selected item exists, obtain the value of the selected item:
Indicate the source for reprinting.