Test code:
Copy Code code as follows:
(function () {
var p=new pevent (document);
P.click (function () {
Alert ("click");
alert (P.style);
var html= "";
For (var item in document) {
html+=item+ ': ' +document[item]+ ' \ r \ n ';
}
alert (HTML);
});
P.dblclick (function () {
Alert ("Double click");
});
P.contextmenu (function (event) {
try{
var X=event.clientx;
var Y=event.clienty;
var menu=g ("menu");
Judging coordinates
var width=document.body.clientwidth;
var height=document.body.clientheight;
x= (x+menu.clientwidth) >=width?width-menu.clientWidth:x;
Y= (y+menu.clientheight) >=height?height-menu.clientHeight:y;
Alert ("Visual height:" +height+ ", Mouse Height:" +y);
menu.style.top=y+ "px";
menu.style.left=x+ "px";
menu.style.display= "Block";
}catch (e) {
Alert (e);
}
return false;
});
function pevent (DOM) {
This.x=function () {
This.style.css=dom.style;
}
This.click=function (FN) {
DOM.ONCLICK=FN;
This.x ();
}
This.dblclick=function (FN) {
DOM.ONDBLCLICK=FN;
}
This.contextmenu=function (FN) {
DOM.ONCONTEXTMENU=FN;
}
This.style=new Po ();
};
function Po () {
This.name=new Object ();
This.id=new Object ();
This.css=new Object ();
}
})();
function g (ID) {
return document.getElementById (ID);
}
In jquery, you can write anonymous methods when handling events, such as:
Copy Code code as follows:
Obj.click (function () {
Alert ("Hello");
});
Appeal in this form.
When the method passes the parameter, the fun method can be passed.
Call, you can call it like this:
Copy Code code as follows:
This.dblclick=function (FN) {
DOM.ONDBLCLICK=FN;
}