IOS處理點空白處不自動失去焦點的問題


objBlurFun("input");
    //如果不是當前觸摸點不在input上,那么都失去焦點
    function objBlurFun(sDom,time){
        var time = time||300;
        //判斷是否為蘋果
        var isIPHONE = navigator.userAgent.toUpperCase().indexOf("IPHONE")!= -1;
        if(isIPHONE){
           var obj = document.querySelectorAll(sDom);
           for(var i=0;i<obj.length;i++){
               objBlur(obj[i],time);
           }
        }
    }    
    // 元素失去焦點隱藏iphone的軟鍵盤
    function objBlur(sdom,time){
         if(sdom){
            sdom.addEventListener("focus", function(){
                    document.addEventListener("touchend", docTouchend,false);
            },false);
                
         }else{
             throw new Error("objBlur()沒有找到元素");
         }
         var docTouchend = function(event){
            if(event.target!= sdom){
                setTimeout(function(){
                     sdom.blur();
                    document.removeEventListener('touchend', docTouchend,false);
                },time);
            }
         };
        
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM