Three methods for JS event creation (instance code) and three methods for js
1. common definition method
<Input type = "button" name = "Button" value = "OK" onclick = "Sfont = prompt ('Enter the red', 'red' in the text box ', 'prompt box '); if (Sfont = 'red') {form1.style. fontFamily = 'simhei '; form1.style. color = 'red';} "/>
This is the most common way to define JS events directly on the desired object. The related deformation is the form of calling the method, as follows:
<script> function show() { alert("show"); }</script><input type="button" name="show" onclick="show()"/>
Second
<script type="text/javascript" for="window" event="onload"> alert("Welcome!");</script><script type="text/javascript" for="window" event="onunload"> alert("Thanks!");</script>
The operations that occur when loading and uninstalling windows are defined here.
For events targeting other objects, you only need to change the for attribute value to the object name and the event to the monitored event. As follows:
<script type="text/javascript" for="test" event="onclick">alert("button!");</script>
Third:
<input type="button" name="test" value="test"/><script>function te(){ alert("test");}test.onclick=te;</script>
Here we use the registration form to register the method to the specified event of the specified object. Use the object name for calling.
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">
The above three methods for creating JS events (instance Code) are all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support for the customer's house.