运行代码 缩小
汉王
HTML代码
复制 格式化 注释 注释 清空
放大
AخA
 
1
请按下键盘上的A键,会跳转到手册网的首页
2
<SCRIPT language="JavaScript">
3
<!--
4
var hotkey=97
5
var destination=""
6
if (document.layers)
7
document.captureEvents(Event.KEYPRESS)
8
function backhome(e){
9
if (document.layers){
10
if (e.which==hotkey)
11
window.location=destination
12
}
13
else if (document.all){
14
if (event.keyCode==hotkey)
15
window.location=destination
16
}
17
}
18
document.onkeypress=backhome
19
onkeydown="javascript:onenter();"
20
function onenter(){
21
 if(event.keyCode==13){
22
alert("回车");
23
}
24
}
25
</SCRIPT>
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
CSS代码...
x
 
1
JS代码
复制 格式化 注释 注释 清空
放大
JS代码...
xxxxxxxxxx
1
 
1
名称
JavaScript接收键盘指令示例
分类
网站常用
描述
JavaScript接收键盘指令示例,按下键盘上不同的键,程序会跳转到不同的网页,本例中按下A键程序为跳转到源码爱好者的首页,实现按键跳转的功能。
收藏