w3pop.com :: ÍøÂçѧԺ :: HTML DOM :: DOM Input Text ¶ÔÏó
The Text object represents a text field in an HTML form. For each instance of an <input type="text"> tag in an HTML form, a Text object is created.
Text ¶ÔÏó´ú±íÁËHTML±íµ¥ÖеÄtext field£¬Ã¿µ±HTML±íµ¥ÖгöÏÖ<input type="text">±êÇ©¾ÍÒâζ×ÅText ¶ÔÏó±»½¨Á¢ÆðÀ´ÁË
You can access a Text object by indexing the elements array (by number or name) of the corresponding form or by using getElementById().
Äã¿ÉÒÔ´Ó±íµ¥Êý×éµÄÊý×Ö»òÊÇÃû³ÆÀ´·ÃÎÊText ¶ÔÏ󣬻òÊÇʹÓÃgetELmentById()À´·ÃÎÊËü
IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (Internet Standard).
| 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 text field ÉèÖûò·µ»ØÄܹ»·ÃÎÊ text field µÄ¼üÅ̰´¼ü¡£ |
4 | - | - | Yes |
| align | Sets or returns the alignment of the text field according to the surrounding text ÉèÖûò·µ»Ø text field Ïà¶ÔÖÜΧÎÄ×ÖµÄ¶ÔÆë·½Ê½ |
- | Yes | ||
| alt | Sets or returns an alternate text to display if the browser does not support text fields ÉèÖûò·µ»Ø¶ÔÓÚÄÇЩÎÞ·¨Ö§³Ö text field ä¯ÀÀÆ÷µÄÌæ»»ÎÄ×Ö¡£ |
- | Yes | ||
| defaultValue | Sets or returns the initial value of the text field ÉèÖûò·µ»Ø text fieldµÄ³õʼֵ |
3 | 1 | 2 | Yes |
| disabled | Sets or returns whether or not the text field should be disabled ÉèÖûò·µ»Ø text fieldÊÇ·ñÓ¦¸Ã½ûÓᣠ|
5 | 1 | 6 | Yes |
| form | Returns a reference to the text field's parent form ·µ»Ø°üº¬ text field ±íµ¥µÄ²Î¿¼ |
3 | 1 | 2 | Yes |
| id | Sets or returns the id of the text field (In IE 4 this property is read-only) ÉèÖûò·µ»Ø text fieldµÄid(ÔÚIE4ÖÐÕâ¸öÊôÐÔÖ»¶Á) |
4 | 1 | No | |
| maxLength | Sets or returns the maximum number of characters in the text field ÉèÖûò·µ»Ø text fieldÖÐ×î´óÏÞ¶È×Ö·ûÊý |
4 | 1 | 6 | Yes |
| name | Sets or returns the name of the text field ÉèÖûò·µ»Ø text fieldµÄname |
3 | 1 | 2 | Yes |
| readOnly | Sets or returns whether or not the text field should be read-only ÉèÖûò·µ»Ø text fieldÊÇ·ñΪֻ¶Á |
4 | 1 | 6 | Yes |
| size | Sets or returns the size of the text field ÉèÖûò·µ»Ø text field µÄ´óС |
3 | 1 | 6 | Yes |
| tabIndex | Sets or returns the tab order for the text field ÉèÖûò·µ»Ø text fieldÓÉtab˳ÐòËù¶¨ÒåµÄË÷Òý |
4 | Yes | ||
| type | Returns the type of the form element. For a text object it will always be "text" ·µ»Ø±íµ¥ÔªËØÀàÐÍ£¬ÊÇ text fieldµÄ»°¾Í»á·µ»ØÎª" text field" |
3 | 1 | 3 | Yes |
| value | Sets or returns the value of the value attribute of the text field ÉèÖûò·µ»Ø text field valueÊôÐÔµÄÖµ |
3 | 1 | 2 | Yes |
| Method ·½·¨ |
Description ÃèÊö |
IE | F | N | W3C |
|---|---|---|---|---|---|
| blur() | Removes focus from the text field È¡Ïû text fieldµÄ¾Û½¹ |
4 | 1 | 2 | Yes |
| click() | Simulates a mouse-click in the text field Ä£·ÂÊó±êµã»÷ text field |
4 | No | ||
| focus() | Sets focus on the text field Èà text field »ñµÃ¾Û½¹ |
3 | 1 | 2 | Yes |
| select() | Selects the content of the text field Ñ¡ÖÐ text field µÄÄÚÈÝ |
4 | 1 | 2 | Yes |
Syntax: object.event_name="someJavaScriptCode"
Óï·¨£º¶ÔÏó.ʼþÃû³Æ=“һЩJS´úÂë”
| Event ʼþ |
Description ÃèÊö |
IE | F | N | W3C |
|---|---|---|---|---|---|
| onBlur | Executes some code when the text field loses focus µ± text fieldʧȥ¾Û½¹µÄʱºòÖ´ÐÐһЩ´úÂë |
4 | 1 | 2 | |
| onChange | Executes some code when the text field loses focus and its value has altered µ± text fieldʧȥ¾Û½¹²¢ÇÒËüµÄÖµ·¢Éú±ä¶¯µÄʱºòÖ´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onClick | Executes some code when the user clicks the left mouse button in the text field µ±Óû§ÔÚ text fieldÖÐÓÃÊó±ê×ó¼üµã»÷ʱִÐÐһЩ´úÂë |
4 | |||
| onFocus | Executes some code when the text field gets focus µ± text field»ñµÃ¾Û½¹µÄʱºòÖ´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onKeyDown | Executes some code when a key is pressed in the text field ÔÚ text fieldÖÐÓмü°´×¡µÄʱºòÖ´ÐÐһЩ´úÂë |
4 | 1 | 4 | |
| onKeyPress | Executes some code when an alphanumeric key is pressed in the text field µ± text field ÖÐÓмü°´Ï²¢ÊͷźóÖ´ÐÐһЩ´úÂë |
4 | 1 | 4 | |
| onKeyUp | Executes some code when a key is released in the text field µ± text field Öа´¼üÊÍ·ÅÔòÖ´ÐÐһЩ´úÂë |
4 | 1 | 4 | |
| onSelect | Executes some code when the current selection is changed in the text field µ± text fieldÀﵱǰѡÖеÄÄÚÈÝ·¢Éú±ä»¯Ê±Ö´ÐÐһЩ´úÂë |
3 | 1 | 2 | |
| onSelectStart | Executes some code when some text in the text field is selected µ± text fieldÖÐһЩÎÄ×Ö±»Ñ¡ÖÐÔòÖ´ÐÐһЩ´úÂë |
4 |
ÆÀÂÛ (0)
All