最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js模仿jquery的寫法示例代碼

 更新時(shí)間:2013年06月16日 15:57:40   作者:  
jquery的寫法從事web開發(fā)的人員應(yīng)該不會(huì)陌生吧,下面我們要說(shuō)的是使用js模仿jquery寫法的實(shí)現(xiàn)代碼,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助
測(cè)試代碼:
復(fù)制代碼 代碼如下:

(function(){
var p=new PEvent(document);
p.click(function() {
//alert("單擊");
//alert(p.style);
var html="";
for ( var item in document) {
html+=item+':'+document[item]+"\r\n";
}
//alert(html);
});
p.dblclick(function() {
alert("雙擊");
});
p.contextmenu(function(event) {
try{
var x=event.clientX;
var y=event.clientY;
var menu=g("menu");

//判斷坐標(biāo)
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("可視高度:"+height+",鼠標(biāo)高度:"+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);
}

在jquery中,處理事件的時(shí)候,都可以匿名方法來(lái)寫,例如:
復(fù)制代碼 代碼如下:

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

上訴這種形式。
在方法傳遞參數(shù)的時(shí)候,可以傳遞fun 方法。
調(diào)用呢,就可以這樣調(diào)用:
復(fù)制代碼 代碼如下:

this.dblclick=function(fn){
dom.ondblclick=fn;
}

相關(guān)文章

最新評(píng)論

双辽市| 改则县| 堆龙德庆县| 旬阳县| 鹰潭市| 登封市| 望都县| 嵩明县| 天水市| 旬阳县| 赞皇县| 新疆| 文水县| 沁水县| 仪陇县| 宁波市| 富民县| 阿坝县| 甘南县| 无极县| 云林县| 余姚市| 建阳市| 惠来县| 安新县| 军事| 赤峰市| 象山县| 额敏县| 桦甸市| 光泽县| 天津市| 曲周县| 鄱阳县| 衡东县| 湖北省| 定安县| 吴忠市| 陆良县| 克东县| 舞阳县|