[13年迁移]firefoxfocus为火狐新建焦点事件
生活随笔
收集整理的這篇文章主要介紹了
[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
總結
以上是生活随笔為你收集整理的[13年迁移]firefoxfocus为火狐新建焦点事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java Applet读写client串
- 下一篇: Xstudio+Bugzilla