帝王谷资源网 Design By www.wdxyy.com
本文实例讲述了js实现显示当前状态的导航效果代码。分享给大家供大家参考。具体如下:
这里演示显示当前状态的导航,鼠标点击左侧的导航菜单,右侧的内容就会变换,实际上是一个竖向的TAB选项卡,作为菜单来用的话,它正好可以显示当前的菜单位置,比较经典。
运行效果截图如下:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-show-nav-style-status-codes/
具体代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>显示当前状态的导航</title> <style type="text/css"> body { font-family:verdana; } #content { float:left; width:400px; border:1px solid #ccc; margin-left:20px; padding:2px 10px 10px 10px; } ul { margin:0; padding:0; list-style: none; width:200px; float:left; } ul li { margin:0 0 1px 0; padding:0; } ul li a { display:block; padding:8px; text-decoration:none; background: #eee; color: #039; } ul li a:hover { background: #ffc; } ul li a.selected { background: #c63; color:#fff; } #content div { display:none; } #content div.on { display:block; } </style> <script type="text/javascript"> function applySelectedTo(link) { var ul = document.getElementsByTagName("ul")[0]; // get the first ul tag on the page var allLinks = ul.getElementsByTagName("a"); // get all the links within that ul for (var i=0; i<allLinks.length; i++) { // iterate through all those links allLinks[i].className = ""; // and assign their class names to nothing } link.className = "selected"; // finally, assign class="selected" to our chosen link var allDivs = document.getElementsByTagName("div"); for (var k=0; k<allDivs.length; k++) { allDivs[k].className = ""; } var lyricId = link.getAttribute("href").split("#")[1]; lyricId = document.getElementById(lyricId); lyricId.className = "on"; } </script> </head> <body> <h1>A list of links (styled, selected state, onclick, return false, and does something)</h1> <ul> <li><a onclick="applySelectedTo(this);return false;" href="#heartbreakHotel">世界七星级宾馆</a></li> <li><a onclick="applySelectedTo(this);return false;" href="#blueSuedeShoes">蓝色梦想</a></li> <li><a onclick="applySelectedTo(this);return false;" href="#houndDog" class="selected">千年等待</a></li> <li><a onclick="applySelectedTo(this);return false;" href="#dontBeCruel">不要忘记我</a></li> <li><a onclick="applySelectedTo(this);return false;" href="#teddyBear">青岛啤酒</a></li> </ul> <div id="content"> <div id="heartbreakHotel"> <h2>Heartbreak Hotel</h2> <p>Well, since my baby left me,<br /> I found a new place to dwell.<br /> Its down at the end of lonely street<br /> At heartbreak hotel.</p> <p>You make me so lonely baby,<br /> I get so lonely,<br /> I get so lonely I could die.</p> <p>And although its always crowded,<br /> You still can find some room.<br /> Where broken hearted lovers<br /> Do cry away their gloom.</p> <p>You make me so lonely baby,<br /> I get so lonely,<br /> I get so lonely I could die.</p> <p>Well, the bell hops tears keep flowin,<br /> And the desk clerks dressed in black.<br /> Well they been so long on lonely street<br /> They aint ever gonna look back.</p> <p>You make me so lonely baby,<br /> I get so lonely,<br /> I get so lonely I could die.</p> <p>Hey now, if your baby leaves you,<br /> And you got a tale to tell.<br /> Just take a walk down lonely street<br /> To heartbreak hotel.</p> </div> <div id="blueSuedeShoes"> <h2>Blue Suede Shoes</h2> <p>Well, its one for the money,<br /> Two for the show,<br /> Three to get ready,<br /> Now go, cat, go.</p> <p>But dont you step on my blue suede shoes.<br /> You can do anything but lay off of my blue suede shoes.</p> <p>Well, you can knock me down,<br /> Step in my face,<br /> Slander my name<br /> All over the place.</p> <p>Do anything that you want to do, but uh-uh,<br /> Honey, lay off of my shoes<br /> Dont you step on my blue suede shoes.<br /> You can do anything but lay off of my blue suede shoes.</p> <p>You can burn my house,<br /> Steal my car,<br /> Drink my liquor<br /> From an old fruitjar.</p> <p>Do anything that you want to do, but uh-uh,<br /> Honey, lay off of my shoes<br /> Dont you step on my blue suede shoes.<br /> You can do anything but lay off of my blue suede shoes.</p> </div> <div class="on" id="houndDog"> <h2>Hound Dog</h2> <p>You aint nothin but a hound dog<br /> Cryin all the time.<br /> You aint nothin but a hound dog<br /> Cryin all the time.<br /> Well, you aint never caught a rabbit<br /> And you aint no friend of mine.</p> <p>When they said you was high classed,<br /> Well, that was just a lie.<br /> When they said you was high classed,<br /> Well, that was just a lie.<br /> You aint never caught a rabbit<br /> And you aint no friend of mine.</p> </div> <div id="dontBeCruel"> <h2>Don't Be Cruel</h2> <p>You know I can be found,<br /> Sitting home all alone,<br /> If you cant come around,<br /> At least please telephone.<br /> Dont be cruel to a heart thats true.</p> <p>Baby, if I made you mad<br /> For something I might have said,<br /> Please, lets forget the past,<br /> The future looks bright ahead,<br /> Dont be cruel to a heart thats true.<br /> I dont want no other love,<br /> Baby its just you Im thinking of.</p> <p>Dont stop thinking of me,<br /> Dont make me feel this way,<br /> Come on over here and love me,<br /> You know what I want you to say.<br /> Dont be cruel to a heart thats true.<br /> Why should we be apart"teddyBear"> <h2>Teddy Bear</h2> <p>Baby let me be,<br /> Your lovin teddy bear<br /> Put a chain around my neck,<br /> And lead me anywhere<br /> Oh let me be<br /> Your teddy bear.</p> <p>I dont wanna be a tiger<br /> Cause tigers play too rough<br /> I dont wanna be a lion<br /> cause lions aint the kind<br /> You love enough.<br /> Just wanna be, your teddy bear<br /> Put a chain around my neck<br /> And lead me anywhere<br /> Oh let me be<br /> Your teddy bear.</p> <p>Baby let me be, around you every night<br /> Run your fingers through my hair,<br /> And cuddle me real tight.</p> </div> </div> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
标签:
js,显示,当前状态,导航
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月31日
2024年10月31日
- 【原神】V5.1攻略 | 纳西妲一图流攻略
- 群星.2003-重遇80·感动今天的都市人2CD【SONY】【WAV+CUE】
- 希文.2024-沉溺【StreetVoice】【FLAC分轨】
- 韩红.2005-精丫麒麟童】【WAV+CUE】
- 2D像素风日式美学动作游戏《雨魂》将登陆Xbox Series
- 《龙腾世纪4》评分造假?仅将评测代码给好评媒体!
- 《怪猎荒野》推出蜘蛛恐惧症设定 蜘蛛秒变史莱姆
- 《张韶涵单8CD+无损单曲合集》[WAV/FLAC][6.5G]
- 自然声带《大自然 雨声 白噪音》[320K/MP3][135.32MB]
- 自然声带《大自然 雨声 白噪音》[FLAC/分轨][416.27MB]
- 2024年度计划曝光!《暗黑破坏神:不朽》X《魔兽世界》11月开启联动
- 逆流而上!成都Wolves后发制人韧性十足!——《第五人格》2024秋季赛第四周赛报
- 复归之刻,七烛庆典,狼人杀七周年掌门表演赛活动来袭!
- 炉石传说野兽流最终阵容推荐 酒馆战棋野兽流最终阵容图文一览
- 炉石传说野猪人流最终阵容推荐 酒馆战棋野猪人流最终阵容图文一览