使用vue.js是否可以在按下一个按钮时模拟另一个按钮的按下?
例如,如果我按下↓ (向下箭头)按钮,我希望它被表示为我按下了TAB按钮。
为什么要实现这个功能的解释:
在单击DropDown列表后,所有元素的列表将打开。在此列表中,我有一个<input>
元素作为搜索框,用于搜索列表中的其他元素(所有其他元素都直接列在该搜索框下面)。当前,当DropDown列表打开时,焦点会自动设置为搜索框。要向下移动到下一个项目,您必须按TAB按钮。但我需要使用↓(向下箭头)按钮来实现这一点。
使用vue.js是否可以在按下一个按钮时模拟另一个按钮的按下?
例如,如果我按下↓ (向下箭头)按钮,我希望它被表示为我按下了TAB按钮。
为什么要实现这个功能的解释:
在单击DropDown列表后,所有元素的列表将打开。在此列表中,我有一个<input>
元素作为搜索框,用于搜索列表中的其他元素(所有其他元素都直接列在该搜索框下面)。当前,当DropDown列表打开时,焦点会自动设置为搜索框。要向下移动到下一个项目,您必须按TAB按钮。但我需要使用↓(向下箭头)按钮来实现这一点。
HTMLElement#focus()
方法。<!-- TEMPLATE -->
<input type="text"
@keydown.up.stop.prevent="prevInput"
@keydown.down.stop.prevent="nextInput"
v-for="i in 5">
// SCRIPT
methods: {
nextInput(e) {
const next = e.currentTarget.nextElementSibling;
if (next) {
next.focus();
}
},
prevInput(e) {
const prev = e.currentTarget.previousElementSibling;
if (prev) {
prev.focus();
}
},
}
<script src="https://unpkg.com/vue@2.5.17"></script>
<div id="app">
<input type="text"
@keydown.up.stop.prevent="prevInput"
@keydown.down.stop.prevent="nextInput"
v-for="i in 5">
</div>
<script>
new Vue({
el: '#app',
methods: {
nextInput(e) {
const next = e.currentTarget.nextElementSibling;
if (next) {
next.focus();
}
},
prevInput(e) {
const prev = e.currentTarget.previousElementSibling;
if (prev) {
prev.focus();
}
},
}
})
</script>
tab
。<div class="tab" ref="tab">
然后捕获箭头点击:
arrowClick() {
this.$refs.tab.click()
}
Uncaught TypeError: this.$refs.tab.click is not a function
。 - juniorjuniorv-on:keyup.up="doSomething"
这个怎么样?然后实现该函数以执行我所需的操作呢? - juniorjunior