乐趣区

关于前端:前端代码集合持续更新

按键解决办法

window.addEventListener("keydown", (e) => {let container = document.querySelector("#container");
  let {key, keyCode, code} = e;
  let template = "";
  [
    {
      title: "e.key",
      content: key == "" ?"Space" : key,
    },
    {
      title: "e.keyCode",
      content: keyCode,
    },
    {
      title: "e.code",
      content: code,
    },
  ].forEach((item) => {template += `<div class="key"><small>${item.title}</small>${item.content}</div>`;
  });
  container.innerHTML = template;
});
退出移动版