JavaScript event-driven and Event Processing

Source: Internet
Author: User
1. Basic Concepts

Javascript is an object-based language. This is different from Java, where Java is an object-oriented language. The basic feature of objects is event-driven ). It simplifies all input changes in an interface. Generally, the mouse or hot key action is called an event, and the action of a series of programs triggered by the mouse or hot key is called an event driver ). We call it an event handler to process events or functions ).

2. Event Processing Program

In JavaScript, Object events are usually handled by functions. The basic format is the same as that of all functions. You can use all the functions described above as event handlers.

The format is as follows:

Function event processing NAME (parameter table ){

Event Processing statement set;

......

}

3. event-driven

Javascript event-driven events are triggered by mouse or hot key actions. It mainly has the following events:

(1) Click Event onclick

An onclick event is generated when you click the mouse button. At the same time, the event handler or code specified by onclick will be called and executed. Usually generated in the following basic objects:

Button (Button Object)

Checkbox (check box) or (check list box)

Radio (single button)

Reset buttons (important button)

Submit buttons (submit button)

For example, you can use the following buttons to activate the change () file:


<Form>
<Input type = "button" Value = "" onClick = "change ()">
</Form>

After the onClick equal sign, you can use your own functions as the event processing program, or use internal functions in JavaScript. You can also directly use JavaScript code. Example:

 

<Input type = "button" value = "" onclick = alert ("this is an example ");

 

2) onChange event

This event is triggered when the input character value of the text or texturea element is changed, and this event is also triggered when the status of an option in the select Table item changes.

Example:

 

<Form>
<Input type = "text" name = "test" value = "test" oncharge = "check ('this. Test)">
</Form>

(3) onSelect event

This event is triggered when the Text in the Text or Textarea object is highlighted.

(4) Get the focus event onFocus

This event is generated when you click Text, textarea, and select objects. In this case, the object becomes the foreground object.

(5) loss of focus onBlur

When a text object, textarea object, and select object no longer have the focus and return to the background, this file is triggered and corresponds to the onFocas event.

(6) load the file onLoad

This event is generated when a document is loaded. OnLoad is used to detect the cookie value when a document is loaded for the first time, and assign a value to it using a variable so that it can be used by the source code.

(7) uninstall the file onUnload

When the Web page exits, the onUnload Event is triggered and the Cookie status can be updated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.