当前位置: 首页 > 图文教程 > 网络编程 > Javascript > jQuery ctrl+Enter shift+Enter实现代码

Javascript
JS 参数传递的实际应用代码分析
prototype与jquery下Ajax实现的差别
用JS写的简单的计算器实现代码
javascript 数组操作实用技巧
JavaScript 中级笔记 第二章
JavaScript 中级笔记 第三章
JavaScript 中级笔记 第四章 闭包
JavaScript 中级笔记 第五章 面向对象的基础
Mootools 1.2教程 函数
Mootools 1.2教程 事件处理
通过Mootools 1.2来操纵HTML DOM元素
Mootools 1.2教程 设置和获取样式表属性
Mootools 1.2教程 输入过滤第一部分(数字)
Mootools 1.2教程 输入过滤第二部分(字符串)
Mootools 1.2教程 Fx.Tween的使用
Mootools 1.2教程 Fx.Morph、Fx选项和Fx事件
MooTools 1.2中的Drag.Move来实现拖放
Mootools 1.2教程 正则表达式
Mootools 1.2教程 定时器和哈希简介
Mootools 1.2教程 滚动条(Slider)

Javascript 中的 jQuery ctrl+Enter shift+Enter实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 278 ::
收藏到网摘: n/a

jQuery中对键盘事件进行了修正 调用函数的时候传入事件即可。 通过事件的which可以找到键码
不过当有组合键的时候还需要注意一下
如ctrl+enter键,虽然都是用e.ctrlKey但是 enter键的键码不是始终为13了
在ff中 判断 ctrl+enter 是 e.ctrlKey && e.which ==13
在ie6中 判断ctrl+enter 是 e.ctrlKey && e.which ==10
示例:
复制代码 代码如下:

$(document).keypress(function(e){
if(e.ctrlKey && e.which == 13 || e.which == 10) {
$("#btn").click();
} else if (e.shiftKey && e.which==13 || e.which == 10) {
$("#btnv").click();
}
})