事件处理

原创 2004年08月20日 15:28:00
 

事件处理

以下的事件可由 JavaScript 发生:

onBlur onChange onClick onFocus onLoad onMouseOver onSelect onSubmit onUnload

onBlur event handler

A blur event occurs when a text or textArea field on a form loses focus. The onBlur event handler executes JavaScript code when a blur event occurs.

Applies to

selection, text, textArea

Examples

xxx Examples to be supplied.


onChange event handler

A change event occurs when a selection, 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.

Applies to

selection, text, textArea

Examples

xxx Examples to be supplied.


onClick event handler

For button or radioButton, JavaScript code to run when a button is clicked. For checkbox, JavaScript code to run when user checks or unchecks an item.

Applies to

button, checkbox, radioButton, link, reset, submit

Examples

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 an anchor to dynamically specify a value for the HREF attribute of the anchor, as shown in the following example:

Go!

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.


onFocus event handler

Executed when input focus enters the field, either by tabbing in or by clicking but not selecting in the field.

Applies to

selection, text, textArea

Examples

xxx Examples to be supplied.


onLoad event handler

A load event occurs when Navigator finishes loading a window or all frames within a FRAMESET. The onLoad event handler executes JavaScript code when a load event occurs.

Use the onLoad event handler within either the <BODY> or the <FRAMESET> tag, for example, <BODY onLoad="...">.

Applies to

document, window

Examples

xxx Examples to be supplied.

See also

onUnload event handler


onMouseOver event handler

Executes when the mouse pointer is over an object. You must return true if you want to set the window.status property with the onMouseOver event handler.

Applies to

link

Examples

By default, the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. In the following example, the onMouseOver event handler provides the custom message "Click this if you dare."

Click me

See onClick for an example of using onMouseOver when the anchor HREF attribute is set dynamically.


onSelect event handler

A select event occurs when a user selects some of the text within a text or textArea field. The onSelect event handler executes JavaScript code when a select event occurs.

Applies to

text, textArea

Examples

xxx Examples to be supplied.


onSubmit event handler

Specifies the JavaScript code to run when a user attempts to submit a form. Return true to allow the form to be submitted; return false to prevent the form from being submitted.

Applies to

form

Examples

In the following example, the onSubmit event handler evaluates the data being submitted to test if it is legal. If the data is legal, the form is submitted; otherwise, the form is not submitted.

form.onSubmit= "if badFormData(this.form) { return false; } else { return true; }"

onUnload event handler

An unload event occurs when you exit a document. The onUnload event handler executes JavaScript code when an unload event occurs.

Use the onUnload event handler within either the <BODY> or the <FRAMESET> tags, for example, <BODY onUnload="...">.

Applies to

document, window

Examples

xxx Examples to be supplied.

See also

onLoad event handler

[疯狂Java笔记]事件处理:Java事件处理模型

1. Java事件处理三要素:     1) 事件源(Event Source):即事件发生的场所,就是指各个组件,如按钮等,点击按钮其实就是组件上发生的一个事件;     2) 事件(Event):...
  • Lirx_Tech
  • Lirx_Tech
  • 2016年03月05日 13:35
  • 2763

android事件处理机制

前言 基于监听的事件 1监听的处理流程 2内部类作为事件监听器类 3外部类形式作为事件监听器类 4使用匿名内部类作为事件监听器类 5Activity作为事件监听器 6绑定到组件事件属性 基于回调的事件...
  • yyg_2015
  • yyg_2015
  • 2016年11月21日 15:27
  • 1579

DOM0级和DOM2级事件处理程序的区别? — 第13.2.2节

一:什么是DOM0级事件处理程序?  DOM0级方法指定的事件处理程序被认为是元素的方法,因此,这时候的事件处理程序是在元素的作用域中执行的;例如DOM0级绑定事件的方法: Do...
  • flyingpig2016
  • flyingpig2016
  • 2016年10月29日 19:11
  • 1466

AndroidStudio自带侧滑导航详解以及头部布局事件处理

  • 2018年01月08日 23:37
  • 19.13MB
  • 下载

android-02-UI基本组件及事件处理.ppt

  • 2014年11月02日 18:18
  • 1001KB
  • 下载

事件处理ListView

  • 2015年02月11日 10:39
  • 1.97MB
  • 下载

ImageButton的焦点及事件处理

  • 2015年01月02日 15:12
  • 158KB
  • 下载

java事件处理机制.pdf

  • 2014年11月28日 09:31
  • 615KB
  • 下载

用Java事件处理机制实现录制回放功能

  • 2010年09月24日 11:14
  • 53KB
  • 下载

第8章 JSF事件处理(熊)课件及示例程序

  • 2009年11月02日 16:10
  • 466KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:事件处理
举报原因:
原因补充:

(最多只允许输入30个字)