w3pop.com :: ÍøÂçѧԺ :: HTML DOM :: DOM Input Checkbox
The Checkbox object represents a checkbox in an HTML form. For each instance of an <input type="checkbox"> tag in an HTML form, a Checkbox object is created.
Checkbox¶ÔÏó¿É´ú±íÒ»¸öHTML±íµ¥ÖеÄcheckbox(¸´Ñ¡¿ò)¡£Ã¿µ±ÓÐ<input type="checkbox">±êÇ©³öÏÖÔÚHTML±íµ¥£¬Ò»¸öCheckbox¶ÔÏó¾Í½¨Á¢ÆðÀ´ÁË¡£
You can access a Checkbox object by indexing the elements array (by number or name) of the corresponding form or by using getElementById().
Äã¿ÉÒÔͨ¹ýÔªËØÊý×éË÷Òý»òÊÇʹÓÃgetElementById()À´·ÃÎÊCheckbox¶ÔÏó¡£
IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (»¥ÁªÍø±ê×¼).
| Property ÊôÐÔ |
Description ÃèÊö |
IE | F | N | W3C |
|---|---|---|---|---|---|
| accept | Sets or returns a list of content types, which the server processing this form will handle correctly ÉèÖûò·µ»ØÄÚÈݵÄÀàÐÍ£¬È÷þÎñÆ÷¸ü׼ȷµÄ´¦ÀíÕâ¸ö±íµ¥ |
- | Yes | ||
| accessKey | Sets or returns the keyboard key to access the checkbox ÉèÖûò·µ»ØÄܹ»·ÃÎÊÕ⸴ѡ¿òµÄ¼üÅ̰´¼ü¡£ |
4 | Yes | ||
| align | Sets or returns the alignment of the checkbox according to the surrounding text ÉèÖûò·µ»Ø¸´Ñ¡¿òÏà¶ÔÖÜΧÎÄ×ÖµÄ¶ÔÆë·½Ê½ |
- | Yes | ||
| alt | Sets or returns an alternate text to display if the browser does not support checkboxes ÉèÖûò·µ»Ø¶ÔÓÚÄÇЩÎÞ·¨Ö§³Öcheckboxä¯ÀÀÆ÷µÄÌæ»»ÎÄ×Ö¡£ |
- | Yes | ||
| checked | Sets or returns whether or not the checkbox is checked ÉèÖûò·µ»ØcheckboxÊÇ·ñ±»Ñ¡ÖÐÁË |
3 | 1 | 2 | Yes |
| defaultChecked | Sets or returns the default value of the checked attribute (true if checked by default and false if not) ÉèÖûò·µ»Ø±»Ñ¡ÖÐÊôÐÔµÄĬÈÏÖµ£¨±»Ä¬ÈϵÄÑ¡ÖÐÔòÎªÕæ£¬²»È»ÔòΪ¼Ù£© |
3 | 1 | 2 | Yes |
| disabled | Sets or returns whether or not the checkbox should be disabled ÉèÖûò·µ»Ø¸´Ñ¡¿òÊÇ·ñÓ¦¸Ã½ûÓᣠ|
3 | 1 | Yes | |
| form | Returns a reference to the form that contains the checkbox ·µ»Ø°üº¬checkbox±íµ¥µÄ²Î¿¼ |
3 | 1 | 2 | Yes |
| id | Sets or returns the id of the checkbox (In IE 4 this property is read-only) ÉèÖûò·µ»ØcheckboxµÄid(ÔÚIE4ÖÐÕâ¸öÊôÐÔÖ»¶Á) |
4 | 1 | No | |
| name | Sets or returns the name of the checkbox ÉèÖûò·µ»ØcheckboxµÄname |
3 | 1 | 2 | Yes |
| tabIndex | Sets or returns the index that defines the tab order for the checkbox ÉèÖûò·µ»ØcheckboxÓÉtab˳ÐòËù¶¨ÒåµÄË÷Òý |
4 | Yes | ||
| type | Returns the type of the form element. For a checkbox it will be "checkbox" ·µ»Ø±íµ¥ÔªËØÀàÐÍ£¬ÊÇcheckboxµÄ»°¾Í»á·µ»ØÎª"checkbox" |
4 | 1 | 3 | Yes |
| value | Sets or returns the value of the value attribute of the checkbox ÉèÖûò·µ»ØcheckboxÊôÐÔµÄÖµ |
3 | 1 | 2 | Yes |
| Property ÊôÐÔ |
Description ÃèÊö |
IE | F | O | W3C |
|---|---|---|---|---|---|
| className | Sets or returns the class attribute of an element ÉèÖûò·µ»ØÔªËصÄclassÊôÐÔ |
5 | 1 | 9 | Yes |
| dir | Sets or returns the direction of text ÉèÖûò·µ»ØÎÄ×Ö·½Ïò |
5 | 1 | 9 | Yes |
| lang | Sets or returns the language code for an element ÉèÖûò·µ»ØÔªËصĴúÂëÓïÑÔ |
5 | 1 | 9 | Yes |
| title | Sets or returns an element's advisory title ÉèÖûò·µ»ØÔªËصÄ×Éѯ±êÌâ |
5 | 1 | 9 | Yes |
| Method ·½·¨ |
Description ÃèÊö |
IE | F | N | W3C |
|---|---|---|---|---|---|
| blur() | Removes focus from the checkbox ɾ³ýcheckboxµÄ½¹¾à |
3 | 1 | 2 | Yes |
| click() | Simulates a mouse-click in the checkbox ÔÚcheckboxÖÐÄ£·ÂÊó±êµã»÷ |
3 | 1 | 2 | Yes |
| focus() | Gives focus to the checkbox Ϊcheckbox¼ÓÉϾ۽¹ |
3 | 1 | 2 | Yes |
Syntax: object.event_name="someJavaScriptCode"
Óï·¨£º¶ÔÏó.ʼþÃû = "һЩjs´úÂë"
| Event ʼþ |
Description ÃèÊö |
IE | F | N | W3C |
|---|---|---|---|---|---|
| onBlur | Executes some code when the checkbox loses focus µ±checkboxʧȥ¾Û½¹µÄʱºòÖ´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onClick | Executes some code when the checkbox is clicked µ±checkbox±»µãµÄʱºòÖ´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onFocus | Executes some code when the checkbox gets focus µ±checkboxµÃµ½¾Û½¹µÄʱºòÖ´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onMouseDown | Executes some code when a mouse button is pressed µ±Êó±ê°´Å¥°´×¡µÄʱºòÖ´ÐÐһЩ´úÂë |
4 | 1 | 4 | |
| onMouseUp | Executes some code when a mouse button is released µ±Êó±ê°´Å¥ÊͷŵÄʱºòÖ´ÐÐһЩ´úÂë |
4 | 1 | 4 |