惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - 挖豆

关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条 javascript得到网址中传递的参数 的处理函数 页面的焦点:window.onfocus javascript 实现随机数 解析 实现随页面滚动的层(最简单效果) 如何用代码设置滚动条的位置? 关于javascript和c#中日期的两点比较--以防在使用ajax时出错 CSS中的overflow css实现圆角 关于Ajax.net 操作和访问 session application request ajax.net 的使用方法--摘自网上 ArrayList用法 最全的DOS命令集. 如何写批处理文件 读取数据库表的列名,表列的数据类型 在.NET中用MICROSOFT的Excel.Application 部件读取Excel表 ASP内置对象详细介绍 提供一个专业提供连接字符串的网站 Excel连接字符串
javascript 网页注册快捷键的函数
挖豆 · 2007-08-23 · via 博客园 - 挖豆

这里给大家推荐一个用来注册快捷键的javascript函数.
文件很小,就4K。点此下载
有了这个函数,就可以方便的使用javascript处理键盘事件了!对于做应用系统的朋友相信很有帮助。使用很简单,这里是作者的发布页:http://www.openjs.com/scripts/events/keyboard_shortcuts/

示例 代码:

<!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="text/html; charset=utf-8" />
<title>处理键盘事件</title>
<script type="text/javascript" src="http://www.xuewolf.com/blog/upload/shortcuts.js"></script>
<style type="text/css">
#hiddiv { border:1px solid #ccc; height:24px; line-height:24px; width:200px; text-align:center; font-size:14px; display:;}
</style>
</head>

<body>
<div id="hiddiv">按Ctrl+D,我就会消失!</div>
<script type="text/javascript">
//弹出一个提示
shortcut("Ctrl+H",function() {
  alert("几天天气不错");
});


//换一个写法  作用:关闭页面
function displayDiv(){
document.getElementById("hiddiv").style.display = "none";
}

shortcut("Ctrl+D",displayDiv);
</script>
</body>
</html>
  
上面是我写的一个简单的例子.用shortcut注册快捷键,第一个参数就是需要注册的快捷键用"+"连接.第二个参数就是执行该事件的回调函数了.

一般的字母键大写小写不限制.

一些特殊键列举在下边了:
Tab
Space
Return
Enter
Backspace
Scroll_lock
Caps_lock
Num_lock
Pause
Insert
Home
Delete
End
Page_up
Page_down
Left
Up
Right
Down
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12