asp学习网: 首页 >> javascript教程 >> javascript基础 >> javascript参考 表单元素的属性和方法 一

javascript参考 表单元素的属性和方法 一

Password

 

A text field on an HTML form that conceals its value by displaying asterisks (*). When the user enters text into the field, asterisks (*) hide entries from view.

defaultValue
A string indicating the default value of a Password object.
属性源 Password

描述
The initial value of defaultValue is null (for security reasons), regardless of the value of the VALUE attribute.
Setting defaultValue programmatically overrides the initial setting. If you programmatically set defaultValue for the Password object and then evaluate it, JavaScript returns the current value.

You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.

form
An object reference specifying the form containing this object.
属性源 Password


描述
每个表单元素都有一个 form 属性用于指向元素的父表单。该属性在事件控制句柄中特别有用,你可能想要由其获得当前表单中其它元素。


name
A string specifying the name of this object.


描述
The name property initially reflects the value of the NAME attribute. Changing the name property overrides this setting. The name property is not displayed on-screen; it is used to refer to the objects programmatically.
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 Password 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() {
var msgWindow=window.open("")
for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) {
msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")
}
}


type
For all Password objects, the value of the type property is "password". This property specifies the form element's type.
属性源 Password

示例
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++) {
document.writeln("<BR>type is " + document.form1.elements[i].type)
}

value
A string that initially reflects the VALUE attribute.
属性源 Password

描述
This string is represented by asterisks in the Password object field. The value of this property changes when a user or a program modifies the field, but the value is always displayed as asterisks.




方法
blur
Removes focus from the object.
方法源 Password


语法
blur()
参数


示例
The following example removes focus from the password element userPass:
userPass.blur() This example assumes that the password is defined as

<INPUT TYPE="password" NAME="userPass">

focus
Gives focus to the password object.
方法源 Password


语法
focus()
参数


描述
Use the focus method to navigate to the password field and give it focus. You can then either programmatically enter a value in the field or let the user enter a value.

示例
In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the Password object and the select method highlights it so the user can reenter the password.
function checkPassword(userPass) {
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
} This example assumes that the Password object is defined as

<INPUT TYPE="password" NAME="userPass">


handleEvent
调用指定事件的控制句柄。
方法源 Password
语法
handleEvent(event)
参数
event 你想要调用的对象的某一事件控制句柄的名称。


select
Selects the input area of the password field.
方法源 Password


语法
select()
参数


描述
Use the select method to highlight the input area of the password field. You can use the select method with the focus method to highlight a field and position the cursor for a user response.

示例
In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the select method highlights the password field and the focus method returns focus to it so the user can reenter the password.
function checkPassword(userPass) {
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
} This example assumes that the password is defined as

<INPUT TYPE="password" NAME="userPass">

from:asp学习网/title:javascript参考 表单元素的属性和方法 一/ time:2007-3-30 19:47:27

本文主题表单

语义化——表单

ASp表单项目的数据传送的例子

使用快捷键提交表单的方法

设计个性化表单的五个技巧

表单中使用颜色选择器(IE)

利用userData实现客户端保存表单数据

表单元件在说什么?---分析表单元件的语义

常用表单格式的五点技巧

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行