Javascript event-driven

Source: Internet
Author: User
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 processing specified by onclick Program Or Code Will be called for execution. 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) Select event onselect
this event is triggered when the text in the text or textarea object is highlighted.
(4) obtain the focus event onfocus
this event is generated when you click Text, textarea, and select object. In this case, the object becomes the foreground object.
(5) loss of focus onblur
this file is triggered when the text object, textarea object, and select object no longer have focus and return to the background, it corresponds to the onfocas event.
(6) Load file onload
this event is generated when the file 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 Source Code .
(7) uninstall the file onUnload
when the web page exits, the onUnload Event is triggered and the cookie status can be updated.
4. Example
Example 1: The following Program is an example of automatic loading and unloading. That is, when an HTML document is loaded, the loadform () function is called, and the unloadform () function is called before exiting the document to enter another HTML document.

Test3_1.htm
<HTML>
<Head>
<Script language = "JavaScript">
<! --
Function loadform (){
Alert ("this is an example of automatic loading! ");
}
Function unloadform (){
Alert ("this is an example of uninstallation! ");
}
// -->
</SCRIPT>
</Head>
<Body onload = "loadform ()" onUnload = "unloadform ()">
<A href = "test.htm"> call </a>
</Body>
</Html>


Example 2: This is a program that obtains the browser version number. The program first displays a wave prompt. The browser version information is displayed.

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.