1a8b697cff4f26806e791dd1ac76fe468113a780.svn-base 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * How to use
  3. * el-dilalog,只需在el-form中指定v-enterToNext,后面的【=”true"】其实可能省略
  4. * <el-from :model ="form" v-enterToNext="true">
  5. * */
  6. export default {
  7. inserted: function(el) {
  8. // let frm = el.querySelector('.el-form');
  9. const inputs = el.querySelectorAll('input')
  10. // 绑定回写事件
  11. for (var i = 0; i < inputs.length; i++) {
  12. inputs[i].setAttribute('keyfocusindex', i)
  13. inputs[i].addEventListener('keyup', (ev) => {
  14. if (ev.keyCode === 13) {
  15. const targetTo = ev.srcElement.getAttribute('keyfocusto')
  16. console.log(ev.srcElement)
  17. if (targetTo) {
  18. var ctlJ = parseInt(targetTo)
  19. if (ctlJ < inputs.length) { inputs[ctlJ].focus() }
  20. } else {
  21. var attrIndex = ev.srcElement.getAttribute('keyfocusindex')
  22. var ctlI = parseInt(attrIndex)
  23. if (ctlI < inputs.length - 1) { inputs[ctlI + 1].focus() }
  24. }
  25. }
  26. })
  27. }
  28. }
  29. }