key-updown.js

来自「这是《JavaScript学习源代码》一书的源代码」· JavaScript 代码 · 共 21 行

JS
21
字号
// specify KEYDOWN and KEYUP event-handlers
window.document.onkeydown = isdown; 
window.document.onkeyup = isup;

// a function to react to KEYDOWN events
function isdown()
{
  window.document.getElementById("bulb").src="on.gif"; 
  document.getElementById("txt").value = "Key is Down";  
}           

// a function to react to KEYUP events
function isup() 
{                  
  window.document.getElementById("bulb").src="off.gif"; 
  document.getElementById("txt").value = "Key is Up";     
} 

/* the second statement in each function deliberately omits the optional 搘indow.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?