Test code:
Copy codeThe Code is 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 ");
// Determine 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 ("visible 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 events anonymously, for example:
Copy codeThe Code is as follows:
Obj. click (function (){
Alert ("hello ");
});
Appeal form.
When passing parameters in a method, you can pass the fun method.
You can call it as follows:
Copy codeThe Code is as follows:
This. dblclick = function (fn ){
Dom. ondblclick = fn;
}