How can I simulate a different button pressed when a button is pressed?

后端 未结 2 1870
予麋鹿
予麋鹿 2021-01-14 19:30

Is it possible using vue.js to simulate another button pressed when a button is pressed?

For example, if I press the (Arrow down) button, I would l

2条回答
  •  时光取名叫无心
    2021-01-14 20:20

    I think you're asking how to simulate a TAB keypress when the user presses DOWN with the goal of moving the focus to the next focusable input.

    Instead of rewriting the key-event, you could call HTMLElement#focus() on the next sibling:

    
    
    
    // SCRIPT
    methods: {
      nextInput(e) {
        const next = e.currentTarget.nextElementSibling;
        if (next) {
          next.focus();
        }
      },
      prevInput(e) {
        const prev = e.currentTarget.previousElementSibling;
        if (prev) {
          prev.focus();
        }
      },
    }
    

    
    
    

提交回复
热议问题