Event tutorials in Javascript

Source: Internet
Author: User

Events are behaviors that can be detected by JavaScript.
Event
Javascript enables us to create dynamic pages. Events are behaviors that can be detected by JavaScript.

Each element in the web page can generate events that can trigger JavaScript Functions. For example, when a user clicks a button, an onclick event is generated to trigger a function. Events are defined on the HTML page.

Event example:
Click
Page or image loading
Hover your mouse over a hotspot on the page
Select input box in the form
Confirmation Form
Keyboard buttons
Note: events are usually used with functions. when an event occurs, the function is executed.

If you need more comprehensive knowledge about events that can be identified by JavaScript, read our full version event reference manual.
Onload and onUnload
When a user enters or leaves the page, the onload and onUnload events are triggered.

The onload event is often used to detect the browser type and version of a visitor, and then load the webpage of a specific version based on the information.

Onload and onUnload events are often used to process cookies created when users enter or exit the page. For example, when a user first enters the page, you can use a message box to ask the user's name. The name is saved in the cookie. When the user enters this page again, you can use another message box to greet the user: "Welcome John Doe! ".
Onfocus, onblur and onchange
Onfocus, onblur, and onchange events are usually used together to verify the form.

The following is an example of using the onchange event. Once the user changes the domain content, the checkemail () function will be called.

<Input type = "text" size = "30" id = "email" onchange = "checkemail ()"> onsubmit
Onsubmit is used to verify all form fields before submitting a form.

The following is an example of using the onsubmit event. When you click the OK button in the form, the checkform () function is called. If the field value is invalid, this submission will be canceled. The Return Value of the checkform () function is true or false. If the return value is true, the form is submitted, and vice versa.

<Form method = "Post" Action = "xxx.htm" onsubmit = "Return checkform ()"> onmouseover and onmouseout
Onmouseover and onmouseout are used to create "dynamic" buttons.

The following is an example of using the onmouseover event. When the onmouseover event is detected, a warning box is displayed:

<A href = "http://www.w3school.com.cn"
Onmouseover = "alert ('an onmouseover event'); Return false">

</A>

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.