共计 381 个字符,预计需要花费 1 分钟才能阅读完成。
按键解决办法
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;
});
正文完