Organize JavaScript event responses learn notes _javascript tips

Source: Internet
Author: User

What is an event

JavaScript to create dynamic pages. Events are behaviors that can be detected by JavaScript. Each element in a Web page can produce events that can trigger JavaScript functions or programs.

1. Mouse click event (onclick)
OnClick is a mouse click event that occurs when the mouse is clicked on a Web page. The program block of the onclick event call is executed, and is usually used with the button.
Example: When we click the button, we trigger the OnClick event and call two numbers and the function add2 ().

  
 

Note: In a Web page, if you use events, you set the event properties in that element.

2, the mouse after the event (onmouseover)
the mouse passes the event, and when the mouse moves over an object, the object triggers the onmouseover event and executes the program called by the onmouseover event.
When the mouse passes the OK button, the message () function is invoked, which pops up the Messages dialog box.

 <! DOCTYPE html>
  
 

3. Mouse move off event (onmouseout)
The mouse moves the event, and executes the onmouseout called program when the mouse moves the current object.
When the mouse moves the "Click me" button, call the message () function, pop-up Messages dialog box.

 <! DOCTYPE html>
  
 

4. Cursor Focus event (onfocus)
When an object in a Web page obtains a node, the program that executes the onfocus call is executed.
When the Drop-down list gets focus, the message () function is invoked, and the dialog box "" Please choose your current career! ”。

 <! DOCTYPE html>
  
 

5, the loss of focal events (onblur)
the onblur event and the onfocus are relative events that trigger the onblur event and execute the invoked program when the cursor leaves the current focused object.

 <! DOCTYPE html>
 
 <! DOCTYPE html>
  
 

7. Text Box content Change event (onchange)
triggers the onchange event by changing the contents of the text box, while executing the invoked program.

 <! DOCTYPE html>
  
 

8. Loading events (onload)
The event occurs immediately after the page load completes, executing the invoked program at the same time.
Note: 1. When the page is loaded, the OnLoad event is triggered and the event is written in the <body> tag.
2. The load page for this section can be understood as opening a new page.
The following code, when loading a new page, pop-up dialog box "load, please wait ...".

<! DOCTYPE html>
  
 

9. Uninstall event (onunload)

When the user exits the page (page close, page refresh, etc.), the OnUnload event is triggered and the invoked program is executed.

Note: Different browsers have different support for onunload events.

 <! DOCTYPE html>
  
 

The test results found that the other browsers did not perform the application only in IE browser.

The above is about nine kinds of state of JavaScript event response, hope to be helpful to everybody's study.

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.