Show the keycode number

类别:编程语言 点击:0 评论:0 推荐:
<html>
<!--//this code by hongseheike-->
<head>
<script language="javascript">
  ns4 = (document.layers) ? true : false;
  ie4 = (document.all) ? true : false;
function keyDown(e){
  if(ns4){
  var nkey=e.which;
  var iekey='现在是ns浏览器';
  var realkey=String.fromCharCode(e.which);
}
  if(ie4){
  var iekey=event.keyCode;
  var nkey='现在是ie浏览器';
  var realkey=String.fromCharCode(event.keyCode);
  if(event.keyCode==32){realkey='\' 空格\''}
  if(event.keyCode==13){realkey='\' 回车\''}
  if(event.keyCode==27){realkey='\' Esc\''}
  if(event.keyCode==16){realkey='\' Shift\''}
  if(event.keyCode==17){realkey='\' Ctrl\''}
  if(event.keyCode==18){realkey='\' Alt\''}
}
  alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey);
}
document.onkeydown = keyDown;
if(ns4){
document.captureEvents(Event.KEYDOWN);}
</script>
</head>
<body>
//Javascript Document
<hr>
<center>
<h3>请按任意一个键。。。。</h3>
</center>
</body>
</html>

本文地址:http://com.8s8s.com/it/it22570.htm