h5手机端input键盘顶起页面和不被顶起页面 禁止input键盘拉起事件

1.顶起页面(当键盘拉起是 移动内容的位置->盒子内容的高度 定位 margin等)


<div v-for="(item, index) in formList" class="formList" :key="index">
        <input v-model="dataValue[item.alias]"
          :placeholder="item.placeholder"
          :type="item.type"
          :error="errorInfo[item.alias]"
          @focus="onFocus(item.alias)" @blur="onBlur()" onkeyup="this.value=this.value.replace(/\s+/g,'')"/>

methods: {
      onFocus (key) {
        var ele = document.getElementsByClassName('button_footer')[0]
        ele.style.position = 'static'
        ele.style.marginTop = '4.68rem'
        ele.style.width = '100%'
      },
      onBlur () {
        var ele = document.getElementsByClassName('button_footer')[0]
        ele.style.position = 'fixed'
        ele.style.bottom = '0.88rem'
        ele.style.width = 'calc(100% - 0.8rem)'
      }
}

转载:https://blog.csdn.net/liurong1028/article/details/84787651

2.不被顶起页面(固定盒子的高度 定位)

var hrt = document.documentElement.clientHeight; //获取当前可视区域的高度存到hrt变量
    window.onload = function(){ //在页面整体加载完毕时
        document.getElementById('app').style.height= hrt+'px'//把获取到的高度赋值给根div
    }

转载:https://blog.csdn.net/chensvv/article/details/81205417?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

3.禁止input 原生键盘事件

  <van-field
      v-model="infoList.idCardNumber"
      type="text"
      name="身份证"
      label="身份证"
      placeholder="请填写身份证"
      maxlength="18"
      @focus="focus"
    />
      //获取焦点
    focus(e) {
      console.log(e, "focusfocusfocus");
      document.activeElement.blur();
      this.show = true;
    },

你可能感兴趣的:(JavaScript)