以下代码解决了ios可输入元素获得焦点之后如何隐藏软键盘的问题(from):
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()没有找到元素');
}
}