1. Mouse click event (onclick)
(1) Syntax: onclick= "message ()";
(2) Role: The mouse click on the page button, will call the corresponding program block, usually with buttons (button) to use
(3) Example:
function add2 () { var numa,numb,sum; Numa=6; Numb=8; Sum=numa+numb; document.write ("Two numbers and for:" +sum); } </script>
2. Mouse over event (onmouseover)
(1) Syntax: onmouseover= "message ()";
(2) Function: The mouse passes the event, when the mouse moves over an object, the object triggers the onmouseover event, and executes the program called by the onmouseover event.
(3) Example:
<! DOCTYPE html>function message () { confirm ("Please enter the password, then click OK!") ); }</script>password:<input name= "password" type= "password" ><input name= "OK" type= "button" value= "OK" onmouseover= "message ()"/></form></body>
3. Mouse Move event (onmouseout)
(1) Syntax: onmouseout= "message ()";
(2) Function: The mouse moves the event, when the mouse moves the current object, the execution of the onmouseout call program.
(3) Example:
<! DOCTYPE html>function message () { alert ("This road is my drive, this tree is my plant, want to live from now on, only point in!") ); }</script>
4. Cursor Focus event (onfocus)
(1) Syntax: onfocus= "message ()";
(2) Function: When the object in the Web page gets a poly point, the program executing the onfocus call is executed.
(3) Example:
<script type= "Text/javascript" > function message () { alert ("Please select, your current occupation!) "); } </script>Please select your occupation:<br> <form> <select name= " Career "onfocus=" message () > <option> students </option> <option> Teachers </option> <option> Engineers </option> <option> actors </option> <option> Accounting </option> </select> </form></body>
5. Cursor out of focus event (onblur)
(1) Syntax: onblur= "message ()";
(2) Function: The onblur event and onfocus are relative events, triggering the onblur event when the cursor leaves the currently focused object and executing the called program.
(3) Example:
<! DOCTYPE html>function message () { alert ("Please make sure you have entered your password and move it away!") ); }</script> User:<input name= "username" Type= "text" value= "Please enter user name!" "> Password:<input name=" password "type=" text "value=" Please enter the password! "onblur=" message () "> </form></body>
6. Content Check Event (onselect)
(1) Syntax: onselect= "message ()";
(2) Function: Select the event, when the text box or text field is selected, trigger the Onselect event, and the program will be executed.
(3) Example:
<! DOCTYPE html>function message () { alert ("You triggered the Check event!") "); } </script> :<br> <textarea Name= "Summary" cols= "rows=" 5 "onselect=" message () "> Please write profile, not less than 200 words! </textarea> </form></body>
7. Text Box content Change event (onchange)
(1) Syntax: onchange= "message ()";
(2) Function: The onchange event is triggered by altering the contents of the text box while executing the called program.
(3) Example:
<! DOCTYPE html>function message () { alert ("You changed the text content!") "); } </script> :<br> <textarea Name= "Summary" cols= "rows=" 5 "onchange=" message () "> Please write profile, not less than 200 words! </textarea> </form></body>
8. Load event (onload)
(1) Syntax: onload= "message ()";
(2) Function: The event occurs immediately after the page is loaded and executes the called program
(3) Example:
<! DOCTYPE html>function message () { alert ("load, please wait ...");} </script> Welcome to learn JavaScript. </body>
(4) Note: 1. when the page loads, the OnLoad event is triggered and the event is written in the <body> tag . 2. Loads the page, which can be understood as opening a new page.
9. Unload Event (OnUnload)
(1) Syntax: window.onunload = message;
(2) Function: When the user exits the page (page close, page refresh, etc.), trigger the OnUnload event, and execute the called program.
(3) Example:
<! DOCTYPE html> = message; function message () { alert ("Are you sure you want to leave this page?") "); } </script> Welcome to learn JavaScript. </body>
Common event responses in JavaScript