📌  相关文章
📜  按下输入时对表单提交做出反应 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:07.749000             🧑  作者: Mango

代码示例1
useEffect(() => {
    const listener = event => {
      if (event.code === "Enter" || event.code === "NumpadEnter") {
        console.log("Enter key was pressed. Run your function.");
        event.preventDefault();
        // callMyFunction();
      }
    };
    document.addEventListener("keydown", listener);
    return () => {
      document.removeEventListener("keydown", listener);
    };
  }, []);