1. 程式人生 > >手動收起ios機input的軟鍵盤

手動收起ios機input的軟鍵盤

//id是input框的id的名字,time是軟鍵盤多少時間消失
function objBlur(id,time){
    if(typeof id != 'string') throw new Error('objBlur()引數錯誤');var obj = document.getElementById(id),
time = time || 300,
docTouchend = function(event){
            if(event.target!= obj){
                setTimeout(function(){
                    obj.blur
(); document.removeEventListener('touchend', docTouchend,false); },time); } }; if(obj){ obj.addEventListener('focus', function(){ document.addEventListener('touchend', docTouchend,false); },false); }else{ throw new Error('objBlur()沒有找到元素');} }