jQuery智能判断是否是当前导航并加标记

代码简介:

jQuery 菜单,可以智能判断是否是当前导航,如果是,则给当前的菜单项添加一个标记,而你的CSS文件并不需要重新定义,完全交给jQuery 来处理,现在有些朋友或许已经明白了,是jQuery让这种智能菜单变得更加有创意。

代码内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery智能判断是否是当前导航并加标记_网页代码站(www.webdm.cn)</title>
<script language="javascript" type="text/javascript" src="http://www.webdm.cn/themes/script/jquery.js"></script>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,p,ul,li,dl,dt,dd{padding:0;margin:0;}
li{list-style:none;}img{border:none;}em{font-style:normal;}
a{color:#555;text-decoration:none;outline:none;blr:this.onFocus=this.blur();}
a:hover{color:#000;text-decoration:underline;}
body{font-size:12px;font-family:Arial,Verdana, Helvetica, sans-serif;word-break:break-all;word-wrap:break-word;}
.clear{height:0;overflow:hidden;clear:both;}
.nav{width:950px; height:29px; margin:20px auto 0;background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) repeat-x 0 -180px;position:relative;}
.navl{position:absolute;left:0;width:3px;height:29px;background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) no-repeat 0 -150px;}
.navr{position:absolute;right:0;width:3px;height:29px;background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) no-repeat right -150px;}
.nav ul{margin-left:10px;}
.nav ul li{float:left;line-height:29px;display:inline;text-align:center;padding-left:5px; font-size:14px;font-weight:bold;background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) no-repeat right -208px;}
.nav ul li a{float:left;color:#FFF; padding:0 10px;}
.nav ul li.select{background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) repeat-x 0 -240px; position:relative;margin-top:-4px;}
.nav ul li.select a{background:url(http://www.webdm.cn/images/20101216/1/navbg.gif) repeat-x right -240px;height:33px;line-height:33px;color:#333; text-indent:-3px;}
</style>
</head>
<body>
<div class="nav">
	<em class="navl"></em>
    <em class="navr"></em>
	<ul>
    	<li><a href="/">首 页</a></li>
        <li><a href="http://www.webdm.cn/">手机卖场</a></li>
        <li><a href="http://www.webdm.cn/">数码天下</a></li>
        <li><a href="http://www.webdm.cn/">时尚女人</a></li>
        <li><a href="http://www.webdm.cn/">家居装饰</a></li>
    </ul>
</div>
<script type="text/javascript">
// nav
$(function shownav(){
	var a1 = $("url");
	var a2 = $(".nav ul li");
	for(var i=0;i<a2.length;i++){
		if(a2[i] == a1){
			$(a2[i]).addClass("select");
			return;
		}
	}
	$(a2[0]).addClass("select");
})
</script>
    <br />
    <p>
        <a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
</body>
</html>
 

转载于:https://www.cnblogs.com/webdm/archive/2011/07/19/2110423.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值