账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么change事件失去焦点没有作用?
    29
    0

    这是子组件中:
    <v-form-item class="pwd reg-cell" required :label="showlabel" prop="vertifyCode">

      <v-input v-model="vertifyCode" @change="send()" name="vertifyCode" placeholder="6位数字手机验证码"></v-input>
      <button type="button" class="uploadfile" id="getcode" @click="getcode">{{SMSCode}}</button>
    </v-form-item>
    

    methods:{

      //发送验证码
    getcode(){
      this.intverTime = 10;
      var $up = $('#getcode');
      this.sentime =setInterval(() => {
        if ( this.intverTime > 0) {
          this.intverTime = this.intverTime -1;
          this.SMSCode = this.intverTime + "s 后重试";
          $up.attr("disabled",true);  
        } else {
          $up.attr("disabled",false);  
          this.SMSCode = "获取验证码";
          clearInterval(this.sentime);
          this.intverTime = 10;
          this.isloading = false;
        }
      }, 1000);
      post(this, api.sendCode, {'phoneNumber': this.phoneNumber }, (response) => {
        if (response.code == 0) {
          // callback();
          console.log('获取验证码成功');
        } else {
          this.SMSCode = "获取验证码";
          // clearInterval(this.sentime);
          this.intverTime = 10;
          this.isloading = false;
        }
      });
    },
    send(){
      console.log(this.vertifyCode);   //没有打印值,说明change事件没有触发,值发送不到父组件中去
      this.$emit('getVal',this.vertifyCode);
      // this.$emit('child-info',this.msgChild)
    }

    },

    //父组件中
    <v-getcode @getVal="phonecode" :phoneNumber="registerParams.phoneNumber" ></v-getcode>
    methods: {

    phonecode(val){
      console.log('接收子组件传过来的code值:'+val);
      this.registerParams.vertifyCode = val;
    },

    }

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • デ可爱型号0′ω0 普通会员 1楼

      在JavaScript中,当失去焦点事件处理函数执行时,焦点可能已被其他操作覆盖。如果焦点没有被其他操作覆盖,那么change事件处理函数可能没有生效。要确保焦点在任何时候都被正确处理,可以使用document.addEventListener()方法来监听焦点事件,然后使用focus()方法来重新获得焦点。

      例如:

      javascript document.addEventListener('change', function(event) { if (event.target !== document.activeElement) { // 其他操作覆盖焦点,无需处理 } else { // 重新获得焦点 document.activeElement.focus(); } });

      这段代码会在元素焦点被改变时执行。如果焦点被其他操作覆盖,那么此事件处理函数不会被执行。如果焦点重新被获取,那么此事件处理函数将被执行。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部