动态生成的一组input,触发enter事件后怎么focus下一个input
<li class="border-none" v-for="(item,index) in prcHdAreaList" :key="item.pmcKeyVal">
<input
:ref="item.pmcKeyVal"
v-focus-next-on-enter="'item.pmcKeyVal'"
name="item.phaRate" class="cus_input"
v-model.trim="item.phaRate" type="number"/>
</li>
Vue.directive('focusNextOnEnter', {
bind: function(el, {value}, vnode) {
el.addEventListener('keyup', (ev) => {
if (ev.keyCode === 13) {
let nextInput = vnode.context.$refs[value]
if (nextInput && typeof nextInput.focus === 'function') {
nextInput.focus()
nextInput.select()
}
}
})
}
})
具体代码(直接复制粘贴便可看到效果,重要地方都做了注释):