<html>
<body>
<p>在输入字段中按下键盘上的一个键,以获取按下的键的 Unicode 字符代码。</p>
<input type="text" size="40" onkeypress="myFunction(event)">
<p id="demo"></p>
<p><strong>注意:</strong> IE8 及更早版本不支持 which 属性。</p>
<script>
function myFunction(event) {
var x = event.which;
document.getElementById("demo").innerHTML = "Unicode 值是:" + x;
}
</script>
</body>
</html>