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 相关文章推荐
IE中jscript/javascript的条件编译
Sep 07 Javascript
基于jQuery的图片剪切插件
Aug 03 Javascript
跨浏览器的事件对象介绍
Jun 27 Javascript
只需20行代码就可以写出CSS覆盖率测试脚本
Apr 24 Javascript
JS实现判断滚动条滚到页面底部并执行事件的方法
Dec 18 Javascript
基于javascript实现句子翻牌网页版小游戏
Mar 23 Javascript
自己封装的一个简单的倒计时功能实例
Nov 23 Javascript
js模拟微博发布消息
Feb 23 Javascript
jQuery实现三级联动效果
Mar 02 Javascript
bootstrap基本配置_动力节点Java学院整理
Jul 14 Javascript
JavaScript实现换肤功能
Sep 15 Javascript
微信小程序如何实现精确的日期时间选择器
Jan 21 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 Hash函数,增强密码安全
2011/02/25 PHP
PHP中VC6、VC9、TS、NTS版本的区别与用法详解
2013/10/26 PHP
PHP数组内存利用率低和弱类型详细解读
2017/08/10 PHP
php实现的支付宝网页支付功能示例【基于TP5框架】
2019/09/16 PHP
PHP常量DIRECTORY_SEPARATOR原理及用法解析
2020/11/10 PHP
Javascript日期对象的dateAdd与dateDiff方法
2008/11/18 Javascript
JavaScript中的toLocaleDateString()方法使用简介
2015/06/12 Javascript
js实现文本框支持加减运算的方法
2015/08/19 Javascript
BootStrap中Datetimepicker和uploadify插件应用实例小结
2016/05/26 Javascript
jQuery处理XML文件的几种方法
2016/06/14 Javascript
Bootstrap Metronic完全响应式管理模板之菜单栏学习笔记
2016/07/08 Javascript
JS 调试中常见的报错问题解决方法
2017/05/20 Javascript
JavaScript实现图片拖曳效果
2017/09/08 Javascript
IE8中jQuery.load()加载页面不显示的原因
2018/11/15 jQuery
NodeJs crypto加密制作token的实现代码
2019/11/15 NodeJs
手动实现把python项目发布为exe可执行程序过程分享
2014/10/23 Python
Python科学计算之NumPy入门教程
2017/01/15 Python
让python 3支持mysqldb的解决方法
2017/02/14 Python
Python登录注册验证功能实现
2018/06/18 Python
python 判断参数为Nonetype类型或空的实例
2018/10/30 Python
python实现移位加密和解密
2019/03/22 Python
python自动生成model文件过程详解
2019/11/02 Python
numpy中三维数组中加入元素后的位置详解
2019/11/28 Python
Python如何基于rsa模块实现非对称加密与解密
2020/01/03 Python
tensorflow2.0保存和恢复模型3种方法
2020/02/03 Python
在TensorFlow中实现矩阵维度扩展
2020/05/22 Python
APM Monaco中国官网:来自摩纳哥珠宝品牌
2017/12/27 全球购物
英国领先的野生鸟类食品供应商:GardenBird
2018/08/09 全球购物
Hello Molly美国:女性时尚在线
2019/08/26 全球购物
年度评优评先方案
2014/06/03 职场文书
技术员岗位职责
2015/02/04 职场文书
海洋天堂观后感
2015/06/05 职场文书
七个非常实用的Python工具包总结
2021/06/15 Python
Python与C++中梯度方向直方图的实现
2022/03/17 Python
青岛市的收音机研制与生产
2022/04/07 无线电
在SQL Server中使用 Try Catch 处理异常的示例详解
2022/07/15 SQL Server