<html>
<head>
KeyPress Test!<hr>
<script language="javascript">
function Display(e){
if(e.keyCode) //判断浏览器 火狐中ASCII放在event.which属性中
keycode = e.keyCode; //IE中ASCII放在event.keyCode属性中
else
keycode = e.which;
if(keycode == 13){ //按下回车
document.getElementById("char").innerHTML += "<br>";
// alert("回车");
}
else if(keycode == 32){ //按下空格
document.getElementById("char").innerHTML += " ";
}
else{
char = String.fromCharCode(keycode);
document.getElementById("char").innerHTML += char;
}
}
</script>
</head>
<body onKeyPress="Display(event);">
<p id="char">
Press follow key;<br>
</p>
</body>
</html>