BaSaRa 目前关心的是UI技术

好久没更新了,今天查了一下在Firefox下解决Event传递的方法,不错

地址:http://blog.joycode.com/lostinet/archive/2005/02/27/44999.aspx

我佛山人的不错:
用了try...catch因为在IE下会报错但对页面没有影响

try { // 让firefox下的event调用像IE下的一样
 window.constructor.prototype.__defineGetter__("event", function(){
 var o = arguments.callee.caller;
 var e;
 while(o != null){
  e = o.arguments[0];
  if(e && (e.constructor == Event || e.constructor == MouseEvent)) return e;
  o = o.caller;
 }
 return null;
});
}catch(e) {}

用了这段函数则可以直接写 event(window.event) 来操作event(Event)对象了,很方便

如果要操作document的事件,好象这个函数无效吧,所以我这样写
 window.document.onkeyup = function(e) {
  var ev = e||window.event;
  if (ev.keyCode==27 && dojo.style.getStyle(dojo.widget.byId('detailDiv').domNode, "display")!="none")
   dojo.widget.byId('detailDiv').domNode.style.display = "none";
 };

posted on 2006-06-28 14:35 BaSaRa 阅读(622) 评论(0)  编辑  收藏 所属分类: Javascript


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

Blog Stats

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜