1. 监听键盘事件源和键盘动作来实现不同的操作
<
script language
=
"
JavaScript
"
for
=
"
document
"
event
=
"
onkeydown
"
>
<!--
//
Form中的控件的名字都为数字如:1,2,3 ...
//
这样在控件比较多的情况下可以比较容易对事件来源进行分类
var
id
=
parseInt(event.srcElement.name);
var
keyid
=
event.keyCode;
![]()
if
(id
>
6
&&
id
<
76
)
...
{ //利用Form中控件的名字判断
![]()
if(event.keyCode>=48 && event.keyCode <= 53 ) ...{//键盘横行数字键0-5的键值
event.srcElement.value = event.keyCode-48;
event.keyCode=9; //Tab键;转至下一项
![]()
}else if(event.keyCode>=0x60 && event.keyCode <= 0x65 )...{//键盘数字部分数字键0-5的键值
event.srcElement.value = event.keyCode-0x60;
event.keyCode=9;
playSound();
}
![]()
if(event.keyCode ==13)...{
event.keyCode =9;
document.form1.elements[id-1].focus();
}
![]()
}
else
...
{
![]()
if(event.keyCode ==13 && event.srcElement.type!='submit' )...{
event.keyCode = 9;
}
}
-->
</
script
>
<
script language
=
"
javascript
"
for
=
"
document
"
event
=
"
onkeydown
"
>
![]()
<!--
![]()
if
(event.keyCode
==
13
&&
event.srcElement.type
!=
'
button
'
&&
event.srcElement.type
!=
'
submit
'
&&
event.srcElement.type
!=
'
reset
'
&&
event.srcElement.type
!=
'
textarea
'
&&
event.srcElement.type
!=
''
)
![]()
event.keyCode
=
9
;
![]()
-->
![]()
</
script
>
2. 利用回车代替Tab键
附:键盘各键对应的键值 | ||
<script language="JavaScript" src="http://blog.csdn.net/ad/468_60home.js" type="text/javascript"></script>
|