六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 158|回复: 0

jQuery web键盘操作

[复制链接]

升级  32%

22

主题

22

主题

22

主题

秀才

Rank: 2

积分
98
 楼主| 发表于 2013-2-7 23:44:04 | 显示全部楼层 |阅读模式
<!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>jQuery Playground</title><link title="green" media="screen" href="css/green.css" type="text/css" rel="stylesheet" /><script type="text/javascript" src="js/jquery.js"></script><script type="text/javascript">           $(document).ready(function(){// hides all DIVs with the CLASS container// and displays the one with the ID 'home' only$(".container").css("display","none");$("#home").css("display","block");// makes the navigation work after all containers have bee hidden showViaLink($("ul#nav li a"));// listens for any navigation keypress activity          $(document).keypress(function(e){switch(e.which){// user presses the "a"case 97:showViaKeypress("#home");break;// user presses the "s" keycase 115:showViaKeypress("#about");break;// user presses the "d" keycase 100:showViaKeypress("#contact");break;// user presses the "f" key case 102:showViaKeypress("#links");}         });                   });                         // shows a given element and hides all others                         function showViaKeypress(element_id){                 $(".container").css("display","none");               // if multiple keys are pressed rapidly this will hide all but the last pressed key's div                $(".container").hide(1);                $(element_id).slideDown("slow");                    }                        // shows proper DIV depending on link 'href'                           function showViaLink(array){                  array.each(function(i)   {        $(this).click(function(){var target = $(this).attr("href");$(".container").css("display","none");$(target).slideDown("slow");});            });                  }</script></head><body><div id="wrapper"><h1>jQuery Playground</h1><ul id="nav"><li><a href="#home">主页(a)</a></li><li><a href="#about">介绍(s)</a></li><li><a href="#contact">联系(d)</a></li><li><a href="#links">链接(f)</a></li></ul><div id="home" class="container"><h2>主页</h2><input type="text" /><br/></div><div id="about" class="container"><h2>介绍</h2></div><div id="contact" class="container"><h2>联系</h2></div><div id="links" class="container"><h2>链接</h2></div><div id="foot">Powered By Dennis Ji.</div></div></body></html> 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表