1. The normal way of defining
<input type= "button" name= button "value=" determines "
onclick=" sfont=prompt (' Please enter red ', ' red ', ' hint box ') in the text box;
if (sfont== ' red ') {
form1.style.fontfamily= ' blackbody ';
Form1.style.color= ' red ';
}
/>
This is the most common way to define the JS event directly above the desired object. The associated deformation is the form of the calling method, as follows
<script>
function Show ()
{
alert (' Show ');
}
</script>
<input type= "button" Name= "Show" onclick= "Show ()"/>
Second Kind
<script type= "text/javascript" for= "window" event= "onload" >
alert ("welcome!");
</script>
<script type= "text/javascript" for= "window" event= "onunload" >
alert ("thanks!");
</script>
This defines the actions that occur when loading and unloading windows.
If it is an event for another object, just modify the value of the for property to the object name, and the event is modified to the monitored events. As follows:
<script type= "Text/javascript" 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 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 ">
Above this JS create event three methods (instance code) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.