在使用hotkeys监听按键的时候点击一个被监听的按键,会出现执行n次(监听n个按键),请问怎么能让他只执行一次呢?代码如下<!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="js/jquery-1.6.2.min.js" ></script>
<script type="text/javascript" src="js/jquery.hotkeys.js" ></script><script>
function demo()
{
$(document).bind('keydown', 'a' ,function(){
alert("a");
return false;});
$(document).bind('keydown', 'b' ,function(){
alert("b");
return false;});
}
$(document).ready(demo);
</script>
</head><body>
press a or b
</body>
</html>点击a会alert两次,如果将代码改为<!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="js/jquery-1.6.2.min.js" ></script>
<script type="text/javascript" src="js/jquery.hotkeys.js" ></script><script>
function demo()
{
$(document).bind('keydown', 'a' ,function(){
alert("a");
return false;});
$(document).bind('keydown', 'b' ,function(){
alert("b");
return false;});
$(document).bind('keydown', 'c' ,function(){
alert("c");
return false;});
}
$(document).ready(demo);
</script>
</head><body>
press a or b
</body>
</html>点击a会alert3次,求解决办法
<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="js/jquery-1.6.2.min.js" ></script>
<script type="text/javascript" src="js/jquery.hotkeys.js" ></script><script>
function demo()
{
$(document).bind('keydown', 'a' ,function(){
alert("a");
return false;});
$(document).bind('keydown', 'b' ,function(){
alert("b");
return false;});
}
$(document).ready(demo);
</script>
</head><body>
press a or b
</body>
</html>点击a会alert两次,如果将代码改为<!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="js/jquery-1.6.2.min.js" ></script>
<script type="text/javascript" src="js/jquery.hotkeys.js" ></script><script>
function demo()
{
$(document).bind('keydown', 'a' ,function(){
alert("a");
return false;});
$(document).bind('keydown', 'b' ,function(){
alert("b");
return false;});
$(document).bind('keydown', 'c' ,function(){
alert("c");
return false;});
}
$(document).ready(demo);
</script>
</head><body>
press a or b
</body>
</html>点击a会alert3次,求解决办法
解决方案 »
- 求助:Ext中的menu可以改变字体或者字体颜色吗?
- 按钮传值问题
- 在stratus 中出现奇怪的问题,总是报错,no FormBeanConfig found under "null'
- 请问已经做了数字签名,为什么还是不能打印?(JasperReport)
- 想做一个项目管理的网站,求助
- 请问jsp中session的有效时间怎么设置,我没有类似找到ASP中的Session.TimeOut???
- 关于session的一个奇怪现象
- 我想点击一个超连接,跳出一个MSAgent的动画人物,怎么实现?
- 我以前装tomcat的时候是选择手动启动服务。现在,我想改成自动启动服务。但我又不想重装tomcat,有什么好的方法吗?
- 请问jsp的入门问题。
- 关于一些语句的疑问
- 问下ec标签导出excel的时候 怎么让身份证号进excel的时候不自动转化为科学计数
{
$(document).bind('keydown', 'a' ,function(){
alert("a");
return false;});
$(document).bind('keydown', 'b' ,function(){
alert("b");
return false;});
$(document).bind('keydown', 'c' ,function(){
alert("c");
return false;});
}
$(document).ready(demo);修改为$(document).bind('keydown', 'a' ,function(){
alert("a");
}
$(document).bind('keydown', 'b' ,function(){
alert("b");
}
$(document).bind('keydown', 'c' ,function(){
alert("c");
}
或者做一个监听事件 ~~然后判断按下去的 KEY值 跟你的 A B C 做判断 你这个代码 好比就是绑定了3个监听事件 每次都会判断 3遍
我更改了一下jquery的版本,从1.6.2改为1.3.2就可以了……
我是按照hotkeys给的demo写的
可能还是jquery版本的问题吧
难道还是老版本的jQuery比较稳定?