The common affirmation is <body onload= "" > This usage. In fact, not only can you use it on the body to support multiple HTML tags. The usage is as follows:
OnLoad event is triggered when a page or a picture is loaded complete.
Supported HTML Tags:
<body>, <frame>, <frameset>, <iframe>, , <link> <script>
Example:
The first of these methods
Copy Code code as follows:
<body onload= "Javascript:alert (' liuzm.com ')" ></BODY>
The second method
Copy Code code as follows:
<script>window.onload=function () {alert (' liuzm.com ')}</script>
<title>event test</title>
<body onload= "init ()" >
<!--binding method one: In the element, the binding methods are set by OnXxx (event)-->
<button id= "BTN1" onclick= "display ()" > Binding mode One </button>
<!--binding Method Two: In JavaScript code, the OnXxx (event) of the element is set to bind methods by obtaining the element-->
<button id= "BTN2" > Binding mode Two </button>
<!--bind Three: Bind event (ie4+) by for, event as element. For the following is element id,event is a specific event-->
<button id= "BTN3" > Binding mode three </button>
<!--binding event (ie5+) for elements by Attachevent. The first argument is the event name, and the second parameter is the method of the binding-->
<button id= "BTN4" > Binding mode Four </button>
</body>
<script type= "Text/javascript" >
function init () {
document.getElementById ("Btn2"). onclick = display;//for button2 binding events
document.getElementById ("Btn4"). Attachevent ("onclick", display);//For Button4 binding event
}
Instance:
Copy Code code as follows:
Function display (event) {
var targ;//an object reference that triggers an event
if (!event) {
var event = window.event;//Get Current event (IE)
}
if (event.target) {//ie has no target
Targ = Evente.target;
} else if (event.srcelement) {//applies to IE
Targ = event.srcelement;
}
//action on the object that triggers the event
Alert (targ.tagname+ "-+targ.id+"-"+event.x+"-"+event.offsetx");
targ.disabled= "Disabled";
}
</script>
<script for= "btn3" event= "onclick" >
Display ()//For Button3 bound events
</scri Pt>