zoukankan      html  css  js  c++  java
  • vue 或者传统h5移动端input被输入法键盘挡住解决方法

    项目里的报名表单中,在没有顶部也没有底部的情况下,正常排版没有用flex布局,当触焦input时,输入法档住了,如下图:

    在这里插入图片描述
    解决方法:

    1.先给最外层的div一个ID取名比如 id="apply"如下图:


    在这里插入图片描述
    2.定义一个class:

    .focusState {position: absolute;}
    

    3.利用监听键盘的收起展开事件来添加移除定义的focusState 样式

      created(){
        var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
        window.onresize = function() {
            var nowClientHeight = document.documentElement.clientHeight || document.body.clientHeight;
            if (clientHeight - nowClientHeight > 60 ) {//因为ios有自带的底部高度
                //键盘弹出的事件处理
                document.getElementById("apply").classList.add("focusState");
            }
            else {
                //键盘收起的事件处理
            	document.getElementById("apply").classList.remove("focusState");
            } 
        };
    },
    

    解决之后的效果:
    在这里插入图片描述


    解决方法二、利用input触焦移焦的写法:
    这里在需要的input标签上同时绑定@click的focusInput和blurInput事件 ,.focusState样式照常,然后如下:

    methods: {
            // focusInput(){
            //     document.getElementById("apply").classList.add("focusState");
            // },
            
            // blurInput(){
            //     document.getElementById("apply").classList.remove("focusState");
            // },
         }
    

    此方法如果在没有移出input焦点时收起键盘的情况下,会出现移除class无效的页面bug ,建议用键盘监听方法

  • 相关阅读:
    MSSQL Rebuild(重建)索引
    网络爬虫原理
    Twitter Storm:单机环境的安装与配置
    1079 回家
    Win2003 Server磁盘配额揭密之补遗篇
    Win2003 Server磁盘配额揭密之启用篇
    编译mapnik(win7 环境下vs2008编译mapnik 0.7.1 成功)
    Writing a Windows Shell Extension(marco cantu的博客)
    Android学习之一:Cygwin简介
    Linux 进程间通信(一)
  • 原文地址:https://www.cnblogs.com/xm0328/p/13900653.html
Copyright © 2011-2022 走看看