JS Instance Tutorial: How to use JavaScript events event

Source: Internet
Author: User
Tags html form

JS Example Tutorial: JavaScript Events method

The action of the event, can detect the JavaScript.

Activities
By using JavaScript, we have the ability to create dynamic Web pages. The action of the event, can detect the JavaScript.

Each element has certain events on the Web page that can trigger JavaScript functions. For example, we can use the OnClick event with the contents of a button to indicate that a function will run when the user presses the button. We identified the HTML tags in the event.

Examples of events:

Click the mouse
A Web page or picture is loaded
The mouse over the hotspot page
Select an input box in an HTML form
Submitting HTML Forms
Hit key
Note: activities are usually combined with functions that are not executed before the event occurs!

For a complete reference event admits JavaScript, to complete our range of activities.

Call and OnUnload
The call and the OnUnload event are triggered when the user enters or leaves the page.

The onload event is often used to check the visitor's browser type and version of the browser and to load the appropriate version of the page information on the basis.

Both the invocation and OnUnload events are often used to process cookies, and should be set when the user enters or leaves the Web page. For example, you can have a pop-up asking the user's name in his first arrival on your page. Name, and then a cookie is stored. The next time a visitor arrives on your page, you can have another pop-up that says: "Welcome John Doe!" ” 。


-------------------------------------------------- ------------------------------

Onfocus, onblur and onchange.
The onfocus, onblur and onchange events are often used in conjunction with the formal validation field.

Here is an example of how to use the onchange event. The Checkemail () function will be called whenever the user changes the Content field:

<input type= "text" size= "30"
id= "Email" onchange= "checkemail ()" >
OnSubmit The OnSubmit event is used to verify all the form fields and then submit. Here is an example of how to use the OnSubmit event. The Checkform () function will be required when the user clicks the Submit button form. If the value of the field is not accepted, the proposal should be canceled. Feature Checkform () returns TRUE or false. If the form returns True, the Commit will be canceled: <form method= "POST" action= "xxx.htm"
Onsubmit= "return Checkform ()" >onmouseover and Onmouseoutonmouseover and onmouseout are often used to make "animated" buttons. The following is an example onmouseover event. When a warning box appears, the onmouseover event is found: <a href= "http://www.w3schools.com"
onmouseover= "alert (' a onmouseover event '); return false" >

</a>

Related Article

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.