NO BB , SHOW ME CODE!
1 objBlurFun("input");
2
3 //如果不是當(dāng)前觸摸點不在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系統(tǒng)軟鍵盤
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/