【问题标题】:Default button without form [closed]没有表单的默认按钮[关闭]
【发布时间】:2019-09-26 09:34:15
【问题描述】:

当用户在键盘上按下 Intro 时,我需要触发一个默认按钮,但是这个 Vue.js 页面没有表单。我应该如何进行?

【问题讨论】:

标签: javascript html vue.js


【解决方案1】:

不确定您所说的介绍是什么意思?我假设您的意思是按下“输入”键时? 试试这个代码lesson

// Get the input field
var input = document.getElementById("myInput");

// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
  // Number 13 is the "Enter" key on the keyboard
  if (event.keyCode === 13) {
    // Cancel the default action, if needed
    event.preventDefault();
    // Trigger the button element with a click
    document.getElementById("myBtn").click();
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多