1. General definition of the way
onclick= "Sfont=prompt (' Please enter the text box in red ', ' red ', ' cue box ');
if (sfont== ' red ') {
form1.style.fontfamily= ' blackbody ';
Form1.style.color= ' Red ';
}"
/>
This is the most common way to define a JS event directly above the desired object. The associated transformation is the form of the calling method, as follows
<script> function Show () { alert ("show"); } </script><input type= "button" Name= "Show" onclick= "show ()"/>
The second Kind
for = "window" event= "onload" > Alert ("welcome!" ); for = "window" event= "onunload" > Alert ("thanks!" ); </script>
This defines what happens when the window is loaded and the window is unloaded.
If the event is for another object, only the value of the for property needs to be modified to the object name, and the event is modified to the monitored events. As follows:
for = "test" event= "onclick" >alert ("button!" ); </script>
The third type:
<input type= "button" name= "Test" value= "test"/><script>function te () { alert (" Test "); Test.onclick=te; </script>
Here we use the form of registration to register the method with the specified event for the specified object. Called by using the object name.
The complete test code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> for= "Window" event= "onload" >Alert ("Welcome!");</script><script type= "Text/javascript" for= "Window" event= "OnUnload" >Alert ("Thanks!");</script><form name= "Form1" method= "Post" action= "" >JS is very studious .</FORM><FORMN ame= "Form2" method= "post" action= "><input type=" button "name=" button "value=" OK " onclick= "Sfont=prompt (' Please enter the text box in red ', ' red ', ' cue box '); if (sfont== ' red ') {form1.style.fontfamily= ' blackbody '; form1.style.color= ' Red ';} ' /><input type= "button" name= "Test" value= "test"/><script>functionte () {Alert ("Test");} Test.onclick=te;</script></form></body>Record, consolidate knowledge, and facilitate others.
You can contact me for communication,[email protected].
2016.5.11
13:52
JS three ways to create events (instance)