按键解决办法
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;
});