NO BB , SHOW ME CODE!
1 objBlurFun("input");
2
3 //如果不是当前触摸点不在input上, 那么都失去焦点
4 function objBlurFun(el, time){
5 const TIME = time || 300;
6 //判断是否为苹果
7 const ISIPHONE = navigator.userAgent.toUpperCase().indexOf("IPHONE") != -1;
8 if(ISIPHONE){
9 let obj = document.querySelectorAll(el);
10 for(let i=0; i<obj.length; i++){
11 objBlur(obj[i], TIME);
12 }
13 }
14 }
15
16 // 元素失去焦点隐藏iphone系统软键盘
17 function objBlur(el, time){
18 if(el){
19 el.addEventListener("focus", function(){
20 document.addEventListener("touchend", docTouchend, false);
21 }, false);
22 }else{
23 throw new Error("objBlur()没有找到元素");
24 }
25
26 let docTouchend = function(event){
27 if(event.target != el){
28 setTimeout(() => {
29 el.blur();
30 document.removeEventListener('touchend', docTouchend, false);
31 }, time);
32 }
33 };
34 }
本文摘自 :https://www.cnblogs.com/