javascript 控制ios textarea 不失去焦点问题

来源:互联网 发布:右下角没有网络图标 编辑:程序博客网 时间:2024/05/16 16:20
//判断是否为苹果var isIPHONE = navigator.userAgent.toUpperCase().indexOf('IPHONE')!= -1;// 元素失去焦点隐藏iphone的软键盘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()没有找到元素');    }}if(isIPHONE){    var input = new objBlur('input');    input=null;}
0 0