我有两个输入框,想要在用户按下回车键时从第一个输入框切换到第二个。 我尝试了使用jQuery和Vue混合编程,因为在Vue文档中找不到任何关于聚焦到某个元素的函数:
<input v-on:keyup.enter="$(':focus').next('input').focus()"
...>
<input ...>
但是在输入后,我在控制台上看到错误:
build.js:11079 [Vue warn]: Property or method "$" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in anonymous component - use the "name" option for better debugging messages.)warn @ build.js:11079has @ build.js:9011keyup @ build.js:15333(anonymous function) @ build.js:10111
build.js:15333 Uncaught TypeError: $ is not a function
v-on:keyup.enter="this.nextSibling.focus()"
。 - Robisebbuild.js:15333 未捕获的类型错误:无法读取未定义的 'focus' 属性
。 - Ivan Borshchov<input id="XX" ...>
。尝试添加一个并更改此行v-on:keyup.enter="document.getElementById('XX').focus()"
。 - Robisebdocument.getElementById('next_id').focus();
,但是它会再次出现build.js:11079 [Vue warn]: Property or method "getElementById" is not defined on the instance but referenced during render
。 - Ivan Borshchov