移动web开发中input等输入框问题
移动端web开发时,input等输入框在安卓和iso中都有问题,分别有:
1.iso不能点击其他区域使得输入框失去焦点
2.iso输入框失去焦点后,键盘产生的空白部分不消失
3.安卓端输入框得到焦点后,输入框不会自动跳转到可视范围 以下是我写的一个案例,对这些问题进行解决。使用vue编写
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html;">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<meta name="format-detection" content="telephone=no,email=no">
</head>
<body>
<div id="app">
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<form action="" id="register">
<div class="sgqformline">
<div class="con infoitem">
<div id="acName" class="inputBox">
<input type="text" name="name" placeholder="请输入您的真实姓名" @focus="isohide($event)" @blur="isoshow($event)" maxlength="40">
</div>
</div>
<div class="wrong_tips"></div>
</div>
<div class="sgqformline">
<div class="con infoitem">
<div id="acMobile" class="inputBox">
<input type="tel" name="mobile" placeholder="请输入手机号" @focus="isohide($event)" data-reg="tel" maxlength="11" @blur="isoshow($event)">
</div>
</div>
<div class="wrong_tips"></div>
</div>
</form>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
<p>测试</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script>
var iso = false;
var nowinput = null;
var myAPP;
var browser={
versions:function(){
var u = navigator.userAgent, app = navigator.appVersion;
return {
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
};
}(),
language:(navigator.browserLanguage || navigator.language).toLowerCase()
};
if(browser.versions.ios){
iso = true;
}
function docTouchend (event){
if (!(event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA')) {
// 如果点击的不是input或者textarea,让iso中输入框失去焦点
if (iso) {
// 延时时间和移动距离可以调整
setTimeout(function(){
nowinput.blur(); //解决iso不能点击其他区域使得输入框失去焦点
window.scrollBy(0,10); // 解决iso失去焦点键盘占据空白不消失
document.removeEventListener('touchend', docTouchend,false);
}, 300);
}
} else {
if (!iso) {
// 解决安卓机再次点击输入框(输入框已获得焦点),输入框不在可视区域
if (nowinput === event.target) {
setTimeout(function () {
event.target.scrollIntoView();
},400)
}
}
}
};
myAPP = new Vue({
data: function () {
return{
}
},
methods: {
isohide: function (e) {
nowinput = e.target;
document.addEventListener("touchend", docTouchend, false);
if (!iso) {
// 解决安卓机点击输入框后,输入框不在可视区域的问题
setTimeout(function () {
e.target.scrollIntoView();
}, 400);
}
},
isoshow: function (e) {
document.removeEventListener('touchend', docTouchend,false);
if (iso) {
// 解决iso失去焦点键盘占据空白不消失
window.scrollBy(0,1);
}
}
},
mounted: function () {
},
filters: { }
})
</script>
</body>
</html>
移动web开发中input等输入框问题的更多相关文章
- Web 开发中 9 个有用的提示和技巧
在本文中,我们给出 9 个有用的 HTML.CSS 和 JavaScript 的技巧和提示,可能在做 Web 开发中经常会需要用到的,其中有几个是关于 HTML5 和 CSS3 的,如果你是一个前端开 ...
- 第123天:移动web开发中的常见问题
一.函数库 underscoreJS _.template: <ol class="carousel-indicators"> <!--渲染的HTML字符串--& ...
- 移动Web 开发中的一些前端知识收集汇总
在开发DeveMobile 与EaseMobile 主题 的时候积累了一些移动Web 开发的前端知识,本着记录总结的目的,特写这篇文章备忘一下. 要说移动Web 开发与传统的PC 端开发,感觉也没什么 ...
- Web开发中设置快捷键来增强用户体验
从事对日外包一年多以来,发现日本的无论是WinForm项目还是Web项目都注重快捷键的使用,日本人操作的时候都喜欢用键盘而不是用鼠标去点,用他们的话来说"键盘永远比鼠标来的快",所 ...
- web开发中的安全问题
web开发中很多东西由前段来负责判断,比如常见的邮箱 电话号码,前端判断到不是一个正确的格式,在你点击提交时候提示你格式填错了,然后不请求后端php,直到你填写正确的格式为止.这种其实可以修改js或者 ...
- web开发中经常使用的js
将自己在web开发中经经常使用到的一些JS总结一下. 1.改动标签和表单的值 改动标签的值: var customer = document.getElementById("custm&qu ...
- Python Web开发中的WSGI协议简介
在Python Web开发中,我们一般使用Flask.Django等web框架来开发应用程序,生产环境中将应用部署到Apache.Nginx等web服务器时,还需要uWSGI或者Gunicorn.一个 ...
- 详细阐述Web开发中的图片上传问题
Web开发中,图片上传是一种极其常见的功能.但是呢,每次做上传,都花费了不少时间. 一个"小功能"花费我这么多时间,真心不愉快. So,要得认真分析下原因. 1.在最初学习Java ...
- 【初码干货】使用阿里云对Web开发中的资源文件进行CDN加速的深入研究和实践
提示:阅读本文需提前了解的相关知识 1.阿里云(https://www.aliyun.com) 2.阿里云CDN(https://www.aliyun.com/product/cdn) 3.阿里云OS ...
随机推荐
- flutter 自定义输入框组件
一.组件分析 ui如下 根据UI分析我们需要提取哪些是动态的,可以通过传递参数得到不同的结果? 1.左侧icon 2.输入的文本 3.是否是密码框 4.输入框的控制器:如何时时得到输入框的值 二.快速 ...
- 爬虫-----selenium模块自动爬取网页资源
selenium介绍与使用 1 selenium介绍 什么是selenium?selenium是Python的一个第三方库,对外提供的接口可以操作浏览器,然后让浏览器完成自动化的操作. sel ...
- 魅族资深DBA:利用MHA构建MySQL高可用平台
龙启东 魅族资深DBA 负责MySQL.Redis.MongoDB以及自动化平台建设 .擅长MySQL高可用方案.SQL性能优化.故障诊断等. 本次分享主要包括以下几方面: 如何利用MHA 改造MHA ...
- 搭建MHA测试
搭建MHA: 手工切换: masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_maste ...
- jenkin如何实现web版本控制&回退
jenkins本身作为一款运维利器,具备 1. 持续集成 (Continuous integration) 2. 持续交付(Continuous delivery) 3. 持续部署(continuou ...
- mysql 获取昨天数据 utc时间
# yzj邀请昨日数据 SELECT s.id, s.create_at, ch.id, ch.code AS channel, c.id , c.code AS custom, so.id, so. ...
- FB面经 Prepare: Count Unique Island
数unique island, 比如 110000 110001 001101 101100 100000 总共两个unique岛,不是四个 方法可以是记录每次新的岛屿搜索的路径,left,right ...
- Vue相关开源项目库汇总
https://github.com/opendigg/awesome-github-vue http://www.opendigg.com/tags/front-vue README.md 内容 U ...
- C#中的委托(delegate)(个人整理)
Delegate 一.什么是委托? 委托是一种引用类型,它是函数指针的托管版本.在C#中,委托是一种可以把引用存储为函数的类型.委托可以引用实例和静态方法,而函数指针只能引用静态方法.委托的声明非常类 ...
- centos6.5 MySQL数据库的安装
<div id="home"><div id="header"> <div id="blogTitle"> ...