时间:2023-02-11 09:48:56 | 栏目:iOS代码 | 点击:次
亲测 ios 9 ,ios10 系统有效,其他请自行测试,建议通过判断系统类型来动态引入此脚本
var isIPHONE = navigator.userAgent.toUpperCase().indexOf("IPHONE")!= -1; if(isIPHONE){ // 元素失去焦点隐藏iphone的软键盘 function objBlur(obj,time){ var startTime=0,endTime=0, time = !time?30:time, docTouchend = function(event){ endTime = new Date().getTime(); if(event.target!= obj && (endTime - startTime <300)){ setTimeout(function(){ obj.blur(); document.removeEventListener("touchend", docTouchend,false); },time); } }; document.addEventListener("touchstart",function(){ startTime = new Date().getTime(); }); document.addEventListener("touchend", docTouchend,false); } $("input").on("focus",function(){ var id = this.id; var self = this; var H = window.innerHeight; var pos = getPosition(self); if(isIPHONE){ var input = new objBlur(self); input=null; } }); function getPosition(target) { var left = 0, top = 0; do { left += target.offsetLeft || 0; top += target.offsetTop || 0; target = target.offsetParent; } while(target); return { left: left, top: top }; } }