js实现显示当前状态的导航效果代码


Posted in Javascript onAugust 28, 2015

本文实例讲述了js实现显示当前状态的导航效果代码。分享给大家供大家参考。具体如下:

这里演示显示当前状态的导航,鼠标点击左侧的导航菜单,右侧的内容就会变换,实际上是一个竖向的TAB选项卡,作为菜单来用的话,它正好可以显示当前的菜单位置,比较经典。

运行效果截图如下:

js实现显示当前状态的导航效果代码

在线演示地址如下:

具体代码如下:

<!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?<br />
  I really love you baby, cross my heart.</p>
  <p>Lets walk up to the preacher<br />
  And let us say I do,<br />
  Then youll know youll have me,<br />
  And Ill know that Ill have you,<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 be cruel to a heart thats true.<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>
 </div>
 <div id="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程序设计有所帮助。

Javascript 相关文章推荐
JavaScript 异步调用框架 (Part 3 - 代码实现)
Aug 04 Javascript
网页防止tab键的使用快速解决方法
Nov 07 Javascript
jquery简单实现网页层的展开与收缩效果
Aug 07 Javascript
js实现的页面矩阵图形变换特效
Jan 26 Javascript
jQuery实现图片轮播效果代码
Sep 27 Javascript
修改 bootstrap table 默认detailRow样式的实例代码
Jul 21 Javascript
关于react中组件通信的几种方式详解
Dec 10 Javascript
Vue2.0 给Tab标签页和页面切换过渡添加样式的方法
Mar 13 Javascript
vue router 跳转后回到顶部的实例
Aug 31 Javascript
基于mpvue搭建微信小程序项目框架的教程详解
Apr 10 Javascript
JS常用正则表达式超全集(密码强度校验,金额校验,IE版本,IPv4,IPv6校验)
Feb 03 Javascript
JS异步宏队列微队列原理详解
Sep 09 Javascript
jQuery实现表单步骤流程导航代码分享
Aug 28 #Javascript
AngularJS+Node.js实现在线聊天室
Aug 28 #Javascript
JS实现仿苹果底部任务栏菜单效果代码
Aug 28 #Javascript
jquery实现弹出层登录和全屏层注册特效
Aug 28 #Javascript
jquery实现多条件筛选特效代码分享
Aug 28 #Javascript
jquery实现的用户注册表单提示操作效果代码分享
Aug 28 #Javascript
js实现横向伸展开的二级导航菜单代码
Aug 28 #Javascript
You might like
一个颜色轮换的简单例子
2006/10/09 PHP
smarty模板嵌套之include与fetch性能测试
2010/12/05 PHP
PHP不用递归遍历目录下所有文件的代码
2014/07/04 PHP
PHP脚本自动识别验证码查询汽车违章
2016/12/20 PHP
PHP魔术方法之__call与__callStatic使用方法
2017/07/23 PHP
捕获关闭窗口的脚本
2009/01/10 Javascript
js对象数组按属性快速排序
2011/01/31 Javascript
仅Firefox中链接A无法实现模拟点击以触发其默认行为
2011/07/31 Javascript
ff下JQuery无法监听input的keyup事件的解决方法
2013/12/12 Javascript
express的中间件bodyParser详解
2014/12/04 Javascript
jQuery validate插件submitHandler提交导致死循环解决方法
2016/01/21 Javascript
JavaScript 消息框效果【实现代码】
2016/04/27 Javascript
jquery实现垂直和水平菜单导航栏
2020/08/27 Javascript
JS实现探测网站链接的方法【测试可用】
2016/11/08 Javascript
JS正则匹配URL网址的方法(可匹配www,http开头的一切网址)
2017/01/06 Javascript
NodeJS配置HTTPS服务实例分享
2017/02/19 NodeJs
Vue-Router基础学习笔记(小结)
2018/10/15 Javascript
vue中axios实现数据交互与跨域问题
2019/05/12 Javascript
javascript 原型与原型链的理解及应用实例分析
2020/02/10 Javascript
python pickle 和 shelve模块的用法
2013/09/16 Python
用python + hadoop streaming 分布式编程(一) -- 原理介绍,样例程序与本地调试
2014/07/14 Python
Python远程桌面协议RDPY安装使用介绍
2015/04/15 Python
利用python将图片转换成excel文档格式
2017/12/30 Python
python执行CMD指令,并获取返回的方法
2018/12/19 Python
Pycharm最新激活码2019(推荐)
2019/12/31 Python
TensorFLow 变量命名空间实例
2020/02/11 Python
python查看矩阵的行列号以及维数方式
2020/05/22 Python
Keras实现支持masking的Flatten层代码
2020/06/16 Python
利用python+ffmpeg合并B站视频及格式转换的实例代码
2020/11/24 Python
Matlab使用Plot函数实现数据动态显示方法总结
2021/02/25 Python
日语专业毕业生自荐信
2013/11/11 职场文书
婚前保证书
2014/04/29 职场文书
2015年小学生暑假总结
2015/07/13 职场文书
2016年党校科级干部培训班学习心得体会
2016/01/06 职场文书
会计工作自我鉴定范文
2019/06/21 职场文书
UNION CREATIVE《Re:从零开始的异世界生活》雷姆手办
2022/03/20 日漫