Text box on the page has loaded gets the focus

Page load will make a text box gets the focus
when the cursor loses focus, the text box will automatically receive focus
after the cursor clicks, you can still jump
document.getElementById ( "input1") focus ( );. // Gets Focus

<template>
  <div>
    <el-input v-model="input" @blur="shiquinput" id="input1" placeholder="请输入内容" class="input-form"></el-input>
    <el-input placeholder="请输入内容" class="input-form"></el-input>
    <el-input placeholder="请输入内容" class="input-form"></el-input>
  </div>
</template>
<script>
export default {
  data() {
    return {
      input: ""
    };
  },

  mounted() {
    document.getElementById("input1").focus(); //获取焦点
  },
  methods: {
    shiquinput() {
      console.log("chufale ");
      this.input = "";
      document.getElementById("input1").focus(); //失去焦点后又获取焦点
    }
  }
};
</script>

<style lang="scss" scoped>
.input-form {
  width: 300px;
  margin-top: 20px;
  margin-left: 20px;
}

Guess you like

Origin www.cnblogs.com/IwishIcould/p/12008275.html