數字鍵盤(觸屏鍵盤)

在vue 中 使用觸屏鍵盤 可刪除指定位置的數據   輸入比較簡單這裏不再囉嗦, 主要是刪除

inputDivDel() { // 只能一個一個刪除的
      const index = this.$refs.codeInput.selectionStart; //input 對象光標的位置
      if (index === 0) {
        return;
      }
      let str = this.inputValue; // input 的值
      this.inputValue = str.replace(str[index - 1], "");  // 刪除該位置的內容並賦值給input
      this.$nextTick(() => { // 渲染完畢 再回復光標的位置
        this.$refs.codeInput.selectionStart = index - 1;
        this.$refs.codeInput.selectionEnd = index - 1;
      });
    }
inputDivDel() { // 可以按照模塊刪除的
      const start_index = this.$refs.codeInput.selectionStart;
      const end_index = this.$refs.codeInput.selectionEnd;
      let index;
      if (start_index === 0  && end_index === 0) {
        return;
      }
      if ((start_index === end_index)) {
        this.inputValue = this.inputValue.replace(this.inputValue[start_index - 1], "");
        index = start_index - 1;
      } else {
        this.inputValue = this.inputValue.substring(0,start_index) + this.inputValue.substring(end_index);
        index = start_index;
      }

      this.$nextTick(() => {
        this.$refs.codeInput.selectionStart = index;
        this.$refs.codeInput.selectionEnd = index;
      });
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章