乐趣区

Vue金额监听按键过滤

<input :placeholder="'最高可提现金额:'+totalRevenue+'元'" v-model="drawMoney" @keypress="isNumber($event)">
methods: {isNumber(evt) {evt = (evt) ? evt : window.event;
      let charCode = (evt.which) ? evt.which : evt.keyCode;
      if ((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode !== 46) {evt.preventDefault();
      } else {let idx = this.drawMoney.indexOf('.');
        (idx > 0) && (idx + 2 < this.drawMoney.length) && evt.preventDefault();
        console.log(this.drawMoney)
      }
    }
}
退出移动版