[13年迁移]firefoxfocus为火狐新建焦点事件

众所周知,firefox下的element除了有tab线的,其他没有焦点这个概念(你可以给一般元素加tabindex属性使得它有焦点).那没有,为什么不自己做一个.

 1 //Just can be running in firefox studio
 2 if(document.addEventListener)
 3   document.addEventListener("click",function (event){firefoxfocuschange(event);} , false);
 4   //The ie brower does not support the function
 5 var lastfocus=new Object;//Get a Object to pass the script interpreter
 6 var currentfocus=null;//供其他方法使用的焦点设置
 7 function firefoxfocuschange(e){
 8     var e=e||window.event;//Compatibility, can be removed,because not to be running in ie studio
 9     var newfocus=e.target||e.srcElement;//ditto
10     if(lastfocus!=newfocus){//console.log("focuschange");
11       if(!lastfocus.tabindex){//console.log("notabindex");//Check element has property for tabindex to prevent running twice.
12         if(lastfocus.onblur){//console.log("runblur");
13               lastfocus.onblur();
14                }
15          }
16     }
17     if(currentfocus){
18     lastfocus=currentfocus;currentfocus=null;}//经测试,ff下,监听事件是在onclick方法执行后发生,那么如果用onclick方法改变焦点,那必须为此问题加入这个currentfocus
19 else{
20 lastfocus=newfocus;}
21     }

测 试已通过,注释直接英文写的,本人练习英语中,加上这段自制的脚本,可以直接修复firefox下的onblur问题(其实你也可以加入获得focus事 件),可以运用的一些老项目中去,有时间我再吧这个封装一下,变成模块,需要暴露一个onfocus出去(对于高级语言来说等于继承后覆写),在链式查找 上截住以前的设置焦点设置方法,不让他去到window.onfocus,让onfocus都正常,也不知道给不给就是了,让firefox完全和ie下 的focus事件一样.

转载于:https://www.cnblogs.com/mikueye/p/4006274.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值