Event object: When an event occurs, the browser automatically establishes the object and includes the type of the event, mouse coordinates, and so on.
Properties of the Event object: Format: Event. property.
Some notes:
An event represents the state of an incident, such as the element that triggers the events object, the position and state of the mouse, the key pressed, and so on;
The event object is valid only if it occurs.
Firefox in the event and IE in the different, ie in the global variable, ready to use, Firefox in the parameters to boot to use, is the run-time temporary variables.
In the Ie/opera is the window.event, in Firefox is an event;
And the object of the event, in IE is window.event.srcElement, in Firefox is Event.target,opera both are available.
Binding events
There are usually two ways to bind an event to an object (control) in JS:
First, define a function in the head:
Copy Code code as follows:
<script type= "Text/javascript" >
function ClickHandler ()
{
Do something
Alert ("button is clicked!");
}
</script>
The first method of binding events:
<input type= "button" value= "Button1" onclick= "ClickHandler ();" ><br/>
The second method of binding events:
Copy Code code as follows:
<input type= "button" id= "Button2" value= "Button2" >
<script type= "Text/javascript" >
var v = document.getElementById ("Button2");
V.onclick = ClickHandler; Function name here, not parentheses
</script>
Other instances
Example 1:
Copy Code code as follows:
<! DOCTYPE html>
<title>eventTest.html</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<!--<link rel= "stylesheet" type= "Text/css" href= "./styles.css" >-->
<script>
function MOver (object) {
Object.color = "Red";
}
function Mout (object) {
Object.color = "Blue";
}
</script>
<body>
<font style= "Cursor:help"
onclick= "window.location.href= ' http://www.baidu.com '"
Onmouseover= "MOver (This)" onmouseout= "Mout (This)" > Welcome visit </font>
</body>
Example 2:
Copy Code code as follows:
<! DOCTYPE html>
<title>eventTest2.html</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<!--<link rel= "stylesheet" type= "Text/css" href= "./styles.css" >-->
<body>
<script type= "Text/javascript" >
function GetEvent (event) {
Alert ("Event Type:" + event.type);
}
document.write ("click ...");
Document.onmousedown = getEvent;
</script>
</body>