国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

elementui表格插槽使用的input輸入框,添加鍵盤(pán)快捷鍵上下左右箭頭,獲取焦點(diǎn)

這篇具有很好參考價(jià)值的文章主要介紹了elementui表格插槽使用的input輸入框,添加鍵盤(pán)快捷鍵上下左右箭頭,獲取焦點(diǎn)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

  1. 給表格行、列賦值index;獲取表格的總列數(shù)

在el-table 添加 :cell-class-name="tableRowClassName"

tableRowClassName({row, column, rowIndex, columnIndex}) {
      this.maxColumnIndex = columnIndex   //獲取表格的列數(shù)
      row.index = rowIndex
      column.index = columnIndex
},
  1. 當(dāng)某個(gè)單元格被點(diǎn)擊時(shí) 獲取行列 觸發(fā)及鍵盤(pán)事件

@cell-click="handleCellClick"

handleCellClick(row, column) {
  let activeElement = document.activeElement.nodeName.toLocaleLowerCase()  //當(dāng)前獲取焦點(diǎn)的元素
  //只有Input才有焦點(diǎn)事件
? ?if(activeElement == 'input') {
      //當(dāng)前獲取焦點(diǎn)的元素,屬于表格的第幾行的第幾個(gè)元素
    this.currentClickEl = {
      rowIndex: row.index,
      columnIndex: column.index
    }
    this.keyDown()
  } else {
    this.currentClickEl = null
  }
 },
//添加鍵盤(pán)事件  得到上下左右鍵的點(diǎn)擊;取消tab鍵的默認(rèn)行為
keyDown() {
  let that = this;
  document.onkeydown = (e) => {
    let el = e || e.event || window.enevt || arguments.callee.callee.arguments[0];
    if(!that.currentClickEl) return
    console.log(el.key)
    //上鍵
    if(el && el.key == 'ArrowUp'){
      that.getIdByIndex('row', -1)
    }
    //下
    if(el && el.key == 'ArrowDown'){
      that.getIdByIndex('row', 1)
    }
    //左
    if(el && el.key == 'ArrowLeft'){
      that.getIdByIndex('column', -1)
    }
    //右
    if(el && el.key == 'ArrowRight'){
      that.getIdByIndex('column', 1)
    }
    if(el && el.key == 'Tab') {
      el.preventDefault();   //阻止默認(rèn)行為
    }
  }
},
//判斷:上鍵的時(shí)候:行的Index減1,到0停止
//判斷:下鍵的時(shí)候:行的Index加1,到表格的最后一行停止;表格的最后一行取決于表格數(shù)據(jù)的數(shù)組
//判斷:左鍵的時(shí)候:列的index減1,到index=0停止
//判斷:右鍵的時(shí)候:列的index加1,到表格的最大列數(shù)停止
//給input框賦值動(dòng)態(tài)id,獲取到這個(gè)id;給這個(gè)元素獲取焦點(diǎn)
//判斷:當(dāng)前的元素是不是input框,表格里面判斷是不是都是輸入框,不是的時(shí)候跳到下一個(gè)輸入框
getIdByIndex(type, num) {
  let that = this;
  if(type == 'row') {
    if(num > 0 && that.currentClickEl.rowIndex == that.form.detailsList.length - 1) return
    if(num < 0 && that.currentClickEl.rowIndex == 0) return
    that.currentClickEl.rowIndex = Number(that.currentClickEl.rowIndex) + num
  } else {
    if(num < 0 && that.currentClickEl.columnIndex == 0) {
      that.currentClickEl.columnIndex = 1
      return
    }
    if(num > 0 && that.currentClickEl.columnIndex == that.maxColumnIndex) return
    that.currentClickEl.columnIndex = Number(that.currentClickEl.columnIndex) + num
  }
  let newId = 'id' + String(that.currentClickEl.rowIndex)  + that.currentClickEl.columnIndex
  if(!document.getElementById(newId)) {
    that.getIdByIndex(type, num)
    return
  }
  if(!newId) return
  setTimeout(() => {
    document.getElementById(newId).focus()
  }, 50)
},

給input賦值id文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-781566.html

<el-table-column prop="ss" label="SS" min-width="80" v-if="form.worksId == 3">
    <template slot="header" slot-scope="scope">
      <div class="tableHeader">表頭名稱(chēng)</div>
    </template>
    <template slot-scope="scope">
      <el-input :id="'id' + scope.row.index + scope.column.index" class="tableInput" v-model="scope.row.ss" clearable oninput="value=value.replace(/[^\d\.]/g,'')"></el-input>
    </template>
</el-table-column>

到了這里,關(guān)于elementui表格插槽使用的input輸入框,添加鍵盤(pán)快捷鍵上下左右箭頭,獲取焦點(diǎn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包