Javascript(一)

event keyboard javascript

抓取鍵盤按鍵按下的哪個按鍵

press keybord

html

javascript

window.onload=function() 
{  
   var bodys=document.querySelector("body"); //抓取body dom 
   var presskey=document.querySelector(".presskey"); //抓取 顯示 dom 
   bodys.addEventListener("keydown",(e)=>{presskey.innerText=e.key+":"+e.keyCode;}); //監聽keydown事件 
}