a set of radio buttons on an htm form. a set of radio buttons lets the user choose one item from a list.
语法
to define a set of radio buttons, use standard htm 语法 with the addition of the onclick event handler:
<input type="radio" name="radioname" value="buttonvalue" [checked] [onclick="handlertext"]> texttodisplayname="radioname" specifies the name of the radio object. all radio buttons in a group have the same name attribute. you can access this value using the name property.
value="buttonvalue" specifies a value that is returned to the server when the radio button is selected and the form is submitted. this defaults to "on". you can access this value using the value property.
checked specifies that the radio button is selected. you can access this value using the defaultchecked property.
texttodisplay specifies the label to display beside the radio button.
to use a radio button's properties and 用法:
1. radioname[index1].propertyname 2. radioname[index1].methodname(parameters) 3. formname.elements[index2].propertyname 4. formname.elements[index2].methodname(parameters)radioname is the value of the name attribute of a radio object.
index1 is an integer representing a radio button in a radio object.
formname is either the value of the name attribute of a form object or an element in the forms array.
index2 is an integer representing a radio button on a form. the elements array contains an entry for each radio button in a radio object.
propertyname is one of the properties listed below.
methodname is one of the 用法 listed below.
property of
描述
a radio object on a form looks as follows:
a radio object is a form element and must be defined within a <form> tag.
all radio buttons in a radio button group use the same name property. to access the individual radio buttons in your code, follow the object name with an index starting from zero, one for each button the same way you would for an array such as forms: document.forms[0].radioname[0] is the first, document.forms[0].radioname[1] is the second, etc.
properties
用法
event handlers
例子
example 1. the following example defines a radio button group to choose among three music catalogs. each radio button is given the same name, name="musicchoice", forming a group of buttons for which only one choice can be selected. the example also defines a text field that defaults to what was chosen via the radio buttons but that allows the user to type a nonstandard catalog name as well. the onclick event handler sets the catalog name input field when the user clicks a radio button.