可以打印一下el.querySelectorAll(‘input.pop-input.pop-input-default’)选中的元素,组件库不同,元素上的属性名也不太一样
directives: {
enterToNext: {
inserted: function(el) {
let inputs = el.querySelectorAll('input.pop-input.pop-input-default')
// console.log(inputs)
for (var i = 0; i < inputs.length; i++) {
// 绑定回写事件
inputs[i].setAttribute('keyFocusIndex', i)
inputs[i].addEventListener('keyup', ev => {
if (ev.keyCode === 13) {
let targetTo = ev.srcElement.getAttribute('keyFocusTo')
if (targetTo) {
this.$refs[targetTo].$el.focus()
} else {
var attrIndex = ev.srcElement.getAttribute('keyFocusIndex')
var ctlI = parseInt(attrIndex)
if (ctlI < inputs.length - 1) {
inputs[ctlI + 1].focus()
}
}
}
})
}
},
},
},