Home > Web Front-end > JS Tutorial > js imitates jquery writing sample code_javascript skills

js imitates jquery writing sample code_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:32:09
Original
1137 people have browsed it

Test code:

Copy code The 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] "rn";
}
//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");

//Judge 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, when handling events, you can write anonymous methods, for example:
Copy code The code is as follows:

obj.click(function(){
alert("hello");
});

Appeal this form.
When passing parameters in a method, you can pass the fun method.
can be called like this:
Copy code The code is as follows:

this .dblclick=function(fn){
dom.ondblclick=fn;
}
Related labels:
js
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template