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 类的定义和引用 JavaScript高级培训 自定义对象
Apr 27 Javascript
基于JQuery模仿苹果桌面的Dock效果(初级版)
Oct 15 Javascript
jQuery中Form相关知识汇总
Jan 06 Javascript
JavaScript实现Fly Bird小游戏
Dec 15 Javascript
提高JavaScript执行效率的23个实用技巧
Mar 01 Javascript
关于jQuery.ajax()的jsonp碰上post详解
Jul 02 jQuery
Node.js中流(stream)的使用方法示例
Jul 16 Javascript
详解jQuery获取特殊属性的值以及设置内容
Nov 14 jQuery
vue基础之事件v-onclick=&quot;函数&quot;用法示例
Mar 11 Javascript
用Vue编写抽象组件的方法
May 06 Javascript
layui清除radio的选中状态实例
Nov 14 Javascript
Vue解决echart在element的tab切换时显示不正确问题
Aug 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
PHP面相对象中的重载与重写
2017/02/13 PHP
php curl发送请求实例方法
2019/08/01 PHP
9个JavaScript评级/投票插件
2010/01/18 Javascript
JSON 教程 json入门学习笔记
2020/09/22 Javascript
jQuery EasyUI API 中文文档 - TimeSpinner时间微调器
2011/10/23 Javascript
json对象转字符串如何实现
2012/12/02 Javascript
jquery如何把参数列严格转换成数组实现思路
2013/04/01 Javascript
jquery中validate与form插件提交的方式小结
2016/03/26 Javascript
Javascript基础知识盲点总结之函数
2016/05/15 Javascript
jQuery中的一些常见方法小结(推荐)
2016/06/13 Javascript
Vue2.0使用过程常见的一些问题总结学习
2017/04/10 Javascript
vue.js实现刷新当前页面的方法教程
2017/07/05 Javascript
vue .sync修饰符的使用详解
2018/06/15 Javascript
Vue开发实现吸顶效果的示例代码
2018/08/21 Javascript
AngularJS $http post 传递参数数据的方法
2018/10/09 Javascript
vue实现购物车抛物线小球动画效果的方法详解
2019/02/13 Javascript
iview的table组件自带的过滤器实现
2019/07/12 Javascript
Vue中关闭弹窗组件时销毁并隐藏操作
2020/09/01 Javascript
解决vue打包 npm run build-test突然不动了的问题
2020/11/13 Javascript
[00:10]DOTA2全国高校联赛 以DOTA2会友
2018/05/30 DOTA
分析并输出Python代码依赖的库的实现代码
2015/08/09 Python
Python编程之序列操作实例详解
2017/07/22 Python
Python实现的弹球小游戏示例
2017/08/01 Python
轻松理解Python 中的 descriptor
2017/09/15 Python
用Python进行简单图像识别(验证码)
2018/01/19 Python
Django数据库表反向生成实例解析
2018/02/06 Python
2020最新pycharm汉化安装(python工程狮亲测有效)
2020/04/26 Python
Python闭包装饰器使用方法汇总
2020/06/29 Python
微信小程序之html5 canvas绘图并保存到系统相册
2019/06/20 HTML / CSS
YOOX台湾:意大利奢侈品电商
2018/10/13 全球购物
主持人演讲稿
2014/05/13 职场文书
关于护士节的演讲稿
2014/05/26 职场文书
助理政工师申报材料
2014/06/03 职场文书
2014年妇幼保健工作总结
2014/12/08 职场文书
家长对孩子的寒假评语
2015/10/09 职场文书
win10拖拽文件时崩溃怎么解决?win10文件不能拖拽问题解决方法
2022/08/14 数码科技