<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
</head>
<body>
<p>按下按键获取键所处的位置。</p>
<input type="text" size="40" onkeydown="myFunction(event)">
<p>可能返回值:</p>
<ul>
<li>0 代表标准按键 (如 "A")</li>
<li>1 代表左侧按键 (如左侧的 CTRL 键)</li>
<li>2 代表右侧按键 (如右侧的 CTRL 键)</li>
<li>3 代表数字键盘上的按键 (如在数字键盘上的 "2" )</li>
</ul>
<p><strong>注意:</strong> Safari,IE8及更早版本浏览器不支持 location 属性。</p>
<p id="demo"></p>
<script>
function myFunction(event) {
var x = event.location;
document.getElementById("demo").innerHTML = "按键的位置在: " + x;
}
</script>
</body>
</html>