x
 
<!DOCTYPE html>
<html>
<body>
<p>在输入字段中按键盘上的某个键可获取被按下键的 Unicode 字符代码。</p>
<input type="text" size="40" onkeypress="myFunction(event)">
<p id="demo"></p>
<p><b>注释:</b>IE8 及更早版本不支持 charCode 属性。</p>
<script>
function myFunction(event) {
  var x = event.charCode;
  document.getElementById("demo").innerHTML = "The Unicode value is: " + x;
}
</script>
</body>
</html>