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 相关文章推荐
jQuery 开发者应该注意的9个错误
May 03 Javascript
javascript原始值和对象引用实例分析
Apr 25 Javascript
js日期范围初始化得到前一个月日期的方法
May 05 Javascript
json对象与数组以及转换成js对象的简单实现方法
Jun 24 Javascript
用jQuery实现优酷首页轮播图
Jan 09 Javascript
vue使用axios跨域请求数据问题详解
Oct 18 Javascript
JS实现对json对象排序并删除id相同项功能示例
Apr 18 Javascript
Vue在页面数据渲染完成之后的调用方法
Sep 11 Javascript
vue 使某个组件不被 keep-alive 缓存的方法
Sep 21 Javascript
深入理解 TypeScript Reflect Metadata
Dec 12 Javascript
VsCode里的Vue模板的实现
Aug 12 Javascript
React配置子路由的实现
Jun 03 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
PHP4中实现动态代理
2006/10/09 PHP
ie与session丢失(新窗口cookie丢失)实测及解决方案
2013/07/15 PHP
PHP使用Session遇到的一个Permission denied Notice解决办法
2014/07/30 PHP
jQuery+Ajax+PHP“喜欢”评级功能实现代码
2015/10/08 PHP
PHP实现提高SESSION响应速度的几种方法详解
2019/08/09 PHP
javascript中检测变量的类型的代码
2010/12/28 Javascript
jQuery拖动div、移动div、弹出层实现原理及示例
2014/04/08 Javascript
jQuery中get()方法用法实例
2014/12/27 Javascript
浅谈jQuery事件绑定原理
2015/01/02 Javascript
JavaScript测试工具之Karma-Jasmine的安装和使用详解
2015/12/03 Javascript
jQuery中选择器的基础使用教程
2016/05/23 Javascript
JavaScript+Java实现HTML页面转为PDF文件保存的方法
2016/05/30 Javascript
JavaScript中全选、全不选、反选、无刷新删除、批量删除、即点即改入库(在yii框架中操作)的代码分享
2016/11/01 Javascript
Node.js制作简单聊天室
2017/01/12 Javascript
NodeJS仿WebApi路由示例
2017/02/28 NodeJs
koa2使用ejs和nunjucks作为模板引擎的使用
2018/11/27 Javascript
[02:42]岂曰无衣,与子同袍!DOTA2致敬每一位守护人
2020/02/17 DOTA
利用Python获取操作系统信息实例
2016/09/02 Python
利用python程序生成word和PDF文档的方法
2017/02/14 Python
Python随机数用法实例详解【基于random模块】
2017/04/18 Python
Python简单爬虫导出CSV文件的实例讲解
2018/07/06 Python
NumPy 数学函数及代数运算的实现代码
2018/07/18 Python
python实现祝福弹窗效果
2019/04/07 Python
使用Flask-Cache缓存实现给Flask提速的方法详解
2019/06/11 Python
python实现中文文本分句的例子
2019/07/15 Python
浅谈pycharm使用及设置方法
2019/09/09 Python
Python创建数字列表的示例
2019/11/28 Python
美国折扣地毯销售网站:Rugs.com
2020/03/27 全球购物
新西兰最大的天然保健及护肤品网站:HealthPost(直邮中国)
2021/02/13 全球购物
存储过程和sql语句的优缺点
2014/07/02 面试题
Tomcat的缺省是多少,怎么修改
2014/04/09 面试题
校园餐饮创业计划书
2014/01/10 职场文书
母婴店促销方案
2014/03/05 职场文书
党的群众路线教育实践方案
2014/05/11 职场文书
同学会演讲稿
2019/04/02 职场文书
Java处理延时任务的常用几种解决方案
2022/06/01 Java/Android