<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="test/html"; charset="gb2312" />
<title>键盘按键测试</title>
<script type="test/javascript">
var txt="";
var txt2="";
function Event(x){
var obj=document.getElementsByName("intxt");
switch(x){
case 1:
txt="可视按键的Unicode代码为:"+event.keycode;
break;
case 2:
txt="非可视按键(Ctrl、Alt、Shift)的Unicode代码为:"+event.keycode;
txt2="非可视按键信息:<br />Alt: "+event.altkey+"<br />Ctrl: "+event.ctrlkey+"<br />Shift: "+event.shiftkey;
break;
case 3:
txt+=String.fromCharcode(event.keyCode);
if(event.keyCode==13){
event.srcElement.blur();
obj[2].focus();
}
break;
case 4:
txt="";
break;
case 5:
txt="焦点移到按钮上去了。"
break;
}
document.getElementById("txt").innerHTML=txt;
document.getElementById("txt2").innerHTML=txt2;
}
</script>
<style type="text/css">
#txt{font-weight:bold;}
</style>
</head>
<body>
<div id="all">
<input type="text" name="intxt" οnkeypress="Event(1);" οnkeydοwn="Event(2);" />
<hr />
提示文字: <span id="txt"></span>
<br />
提示文字: <span id="txt2"></span>
<hr />
<input type="text" name="intxt" οnkeypress="Event(3);" οnfοcus="Event(4);" />
<br />
<input type="button" name="intxt" οnfοcus="Event(5);" value="确定" />
</div>
</body>
</html>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="test/html"; charset="gb2312" />
<title>键盘按键测试</title>
<script type="test/javascript">
var txt="";
var txt2="";
function Event(x){
var obj=document.getElementsByName("intxt");
switch(x){
case 1:
txt="可视按键的Unicode代码为:"+event.keycode;
break;
case 2:
txt="非可视按键(Ctrl、Alt、Shift)的Unicode代码为:"+event.keycode;
txt2="非可视按键信息:<br />Alt: "+event.altkey+"<br />Ctrl: "+event.ctrlkey+"<br />Shift: "+event.shiftkey;
break;
case 3:
txt+=String.fromCharcode(event.keyCode);
if(event.keyCode==13){
event.srcElement.blur();
obj[2].focus();
}
break;
case 4:
txt="";
break;
case 5:
txt="焦点移到按钮上去了。"
break;
}
document.getElementById("txt").innerHTML=txt;
document.getElementById("txt2").innerHTML=txt2;
}
</script>
<style type="text/css">
#txt{font-weight:bold;}
</style>
</head>
<body>
<div id="all">
<input type="text" name="intxt" οnkeypress="Event(1);" οnkeydοwn="Event(2);" />
<hr />
提示文字: <span id="txt"></span>
<br />
提示文字: <span id="txt2"></span>
<hr />
<input type="text" name="intxt" οnkeypress="Event(3);" οnfοcus="Event(4);" />
<br />
<input type="button" name="intxt" οnfοcus="Event(5);" value="确定" />
</div>
</body>
</html>