|
【目录】 【上一页】 【下一页】 【索引】
CheckboxA checkbox on an HTML form. A checkbox is a toggle switch that lets the user set a value on or off.
创建源The HTML INPUT tag, with "checkbox" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates appropriate Checkbox objects and puts these objects in the elements array of the corresponding Form object. You access a Checkbox object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.事件句柄描述A Checkbox object on a form looks as follows:
A Checkbox object is a form element and must be defined within a FORM tag. Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded or reset. 属性概览
方法概览
示例示例 1. The following example displays a group of four checkboxes that all appear checked by default:
<B>Specify your music preferences (check all that apply):</B>
<HTML> 参看Form, Radio属性checkedA Boolean value specifying the selection state of the checkbox.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述If a checkbox button is selected, the value of its checked property is true; otherwise, it is false.You can set the checked property at any time. The display of the checkbox button updates immediately when you set the checked property. 参看Checkbox.defaultCheckeddefaultCheckedA Boolean value indicating the default selection state of a checkbox button.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述If a checkbox is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an INPUT tag; however, setting defaultChecked overrides the CHECKED attribute.You can set the defaultChecked property at any time. The display of the checkbox does not update when you set the defaultChecked property, only when you set the checked property. 参看Checkbox.checkedformAn object reference specifying the form containing the checkbox.
描述每个表单元素都有一个 form 属性用于指向元素的父表单。该属性在事件控制句柄中特别有用,你可能想要由其获得当前表单中其它元素。参看FormnameA string specifying the checkbox's name.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述If multiple objects on the same form have the same NAME attribute, an array of the given name is created automatically. Each element in the array represents an individual Form object. Elements are indexed in source order starting at 0. For example, if two Text elements and a Button element on the same form have their NAME attribute set to "myField", an array with the elements myField[0], myField[1], and myField[2] is created. You need to be aware of this situation in your code and know whether myField refers to a single element or to an array of elements.示例In the following example, the valueGetter function uses a for loop to iterate over the array of elements on the valueTest form. The msgWindow window displays the names of all the elements on the form:
newWindow=window.open("http://home.netscape.com")
function valueGetter() { typeFor all Checkbox objects, the value of the type property is "checkbox". This property specifies the form element's type.
示例The following example writes the value of the type property for every element on a form.
for (var i = 0; i < document.form1.elements.length; i++) { valueA string that reflects the VALUE attribute of the checkbox.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。参看Checkbox.checked, Checkbox.defaultChecked方法blurRemoves focus from the checkbox.
语法blur()参数无参看Checkbox.focusclickSimulates a mouse-click on the checkbox, but does not trigger its onClick event handler. The method checks the checkbox and sets toggles its value.
语法click()参数无。示例The following example toggles the selection status of the newAge checkbox on the musicForm form:document.musicForm.newAge.click() focusGives focus to the checkbox.
语法focus()参数无描述Use the focus method to navigate to a the checkbox and give it focus. The user can then toggle the state of the checkbox.参看Checkbox.blurhandleEvent调用指定事件的控制句柄。
语法handleEvent(event)参数
【目录】 【上一页】 【下一页】 【索引】 |