1 //判断是否为苹果
2 var isIPHONE = navigator.userAgent.toUpperCase().indexOf('IPHONE')!= -1;
3
4 // 元素失去焦点隐藏iphone的软键盘
5 function objBlur(id,time){
6 if(typeof id != 'string') throw new Error('objBlur()参数错误');
7 var obj = document.getElementById(id),
8 time = time || 300,
9 docTouchend = function(event){
10 if(event.target!= obj){
11 setTimeout(function(){
12 obj.blur();
13 document.removeEventListener('touchend', docTouchend,false);
14 },time);
15 }
16 };
17 if(obj){
18 obj.addEventListener('focus', function(){
19 document.addEventListener('touchend', docTouchend,false);
20 },false);
21 }else{
22 throw new Error('objBlur()没有找到元素');
23 }
24 }
25
26 if(isIPHONE){
27 var input = new objBlur('input_id');
28 input = null;
29 }