jquery 处理键盘上下方向键时 无效 代码哪有问题呀 求助
$(document).ready(function(){$(window).keydown(function(event){//if(null==event){//ev...
$(document).ready(function(){
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
<!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>
<title>hello world </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 jQuery -->
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
//等待dom元素加载完毕.
$(document).ready(function(){
alert("Hello World!");
});
//test2
$(document).ready(function(){
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
</script>
</head>
<body>
</body>
</html> 展开
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
<!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>
<title>hello world </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 jQuery -->
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
//等待dom元素加载完毕.
$(document).ready(function(){
alert("Hello World!");
});
//test2
$(document).ready(function(){
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
</script>
</head>
<body>
</body>
</html> 展开
1个回答
展开全部
给你改好了,你要知道“event.keyCode”返回的不是数值,要乘一(*1)转换成了数值型。如此才能判断! 希望对你要帮助!
<!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>
<title>hello world </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 jQuery -->
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
//等待dom元素加载完毕.
$(document).ready(function(){
alert("Hello World!");
});
//test2
$(document).ready(function(){
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode*1) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
</script>
</head>
<body>
</body>
</html>
<!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>
<title>hello world </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 jQuery -->
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
//等待dom元素加载完毕.
$(document).ready(function(){
alert("Hello World!");
});
//test2
$(document).ready(function(){
$(window).keydown(function(event){
//if (null == event) {
//event = window.event;
//}
switch(event.keyCode*1) {
case 38:
alert("38!");
break;
case 40:
alert("40");
break;
}
});
});
</script>
</head>
<body>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询