当前页面: 开发资料首页 → Javascript 专题 → javascript手冊-o
摘要: javascript
A blur event occurs when a select, text, or textarea field on a form loses focus. The onBlur event handler executes JavaScript code when a blur event occurs.
See the relevant objects for the onBlur 语法.
select, text, textarea
In the following example, userName is a required text field. When a user attempts to leave the field, the onBlur event handler calls the required() function to confirm that userName has a legal value.
<input TYPE="text" VALUE="" NAME="userName" onBlur="required(this.value)">
A change event occurs when a select, text, or textarea field loses focus and its value has been modified. The onChange event handler executes JavaScript code when a change event occurs.
Use the onChange event handler to validate data after it is modified by a user.
See the relevant objects for the onChange 语法.
select, text, textarea
In the following example, userName is a text field. When a user attempts to leave the field, the onBlur event handler calls the checkValue() function to confirm that userName has a legal value.
<input TYPE="text" VALUE="" NAME="userName" onBlur="checkValue(this.value)">
A click event occurs when an object on a form is clicked. The onClick event handler executes JavaScript code when a click event occurs.
See the relevant objects for the onClick 语法.
button, checkbox, radio, link, reset, submit
For example, suppose you have created a JavaScript function called compute(). You can execute the compute() function when the user clicks a button by calling the function in the onClick event handler, as follows:
<input TYPE="button" VALUE="Calculate" onClick="compute(this.form)">
In the above example, the keyword this refers to the current object; in this case, the Calculate button. The construct this.form refers to the form containing the button.
For another example, suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of a link to specify a value for the HREF attribute of the tag dynamically, as shown in the following example: In the above example, the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows, you must return true to set the window.status property in the onMouseOver event handler.
A focus event occurs when a field receives input focus by tabbing with the keyboard or clicking with the mouse. Selecting within a field results in a select event, not a focus event. The onFocus event handler executes JavaScript code when a focus event occurs.
See the relevant objects for the onFocus 语法.
select, text, textarea
The following example uses an onFocus handler in the valueField textarea object to call the valueCheck() function. A load event occurs when Navigator finishes loading a window or all frames within a
onFocus event handler
Event Handler of
例子
<input TYPE="textarea" VALUE="" NAME="valueField" onFocus="valueCheck()">
相关
onLoad event handler