JavaScript allows IE browser event objects to conform to the _javascript techniques of the Web DOM standard

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<body>
<input id= "Butt" type= "button" value= "Submit"/>
</body>
<script type= "Text/javascript" >
var eventutil = {};
Eventutil.formatevent = function (oevent) {
if (window. ActiveXObject) {
The CharCode property of the event, the Unicode value of the pressed key
Oevent.charcode = (Oevent.type = = ' KeyPress ')? oevent.keycode:0;
Eventphase properties for the event of the Consortium
The phase of the event, which may have one of the following values:
0-Capture phase
1-On the target
2-bubbling phase
Oevent.eventphase = 2;
The Ischar property of the event, which indicates whether the pressed key has a character associated with it
Oevent.ischar = (Eventutil.charcode > 0);
The Pagex property of the event, the x-coordinate of the mouse relative to the page
Oevent.pagex = Oevent.clientx + document.body.scrollLeft;
The Pagey property of the Web event, the y-coordinate of the mouse relative to the page
Oevent.pagey = Oevent.clienty + document.body.scrollTop;
Preventdefault method of the event, blocking the default behavior of events
Oevent.preventdefault = function () {
This.returnvalue = false;
};
The Relatedtarget property of the common event, the second target of events, often used for mouse events
if (Oevent.type = = ' Mouseout ') {
Oevent.relatedtarget = oevent.toelement;
}else if (Oevent.type = = ' MouseOver ') {
Oevent.relatedtarget = oevent.fromelement;
}
Stoppropagation method for the event of the consortium, canceling the bubbling event
Oevent.stoppropagation = function () {
This.cancelbubble = true;
};
Target attribute of the Consortium event
Oevent.target = oevent.srcelement;
The timestamp property of the consortium event, creates the current time, and returns the number of milliseconds
Oevent.time = (new Date ()). GetTime ();
}
return oevent;
};
Eventutil.getevent = function () {
if (window.event) {
Return event object under IE
Return this.formatevent (window.event);
}else{
Return event object under the Consortium
return eventutil.getevent.caller.arguments[0];
}
};
document.getElementById (' butt '). onclick = function () {
var oevent = eventutil.getevent ();
alert (oevent);
};
</script>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.