当前位置: 代码迷 >> JavaScript >> 领航点击背景颜色
  详细解决方案

领航点击背景颜色

热度:365   发布时间:2013-12-13 13:57:17.0
导航点击背景颜色
<UL>
  <LI><A class="bianse" href="a.aspx">导航一</A> </LI>
  <LI><A href="b.aspx">导航二</A> </LI>
  <LI><A href="c.aspx">导航三</A> </LI>
</UL


class=bianse是控制变色的
点击哪个导航就变色 其他的还原
菜鸟求帮助

------解决方案--------------------
加个css就好了

<style type="text/css">
    a:link,a:visited {
        background-color:red;
    }
    a:hover,a:active {
        background-color:blue;
    }
</style>


具体颜色可以自己改下 

另外提一下  html标签用大写是什么习惯?
------解决方案--------------------
<style type="text/css">
ul li{ width:60px; height:20px; background:#CCC; color:#000;}
ul li a{ width:60px; height:20px; display:inline-block;}
ul li.cur{ background:#EEE;}
</style>
<script type="text/javascript">
$(function(){
$("ul li").click(function(){
$(this).addClass("cur").siblings().removeClass("cur");
})
})
</script>
楼主的结束标签没写完整
------解决方案--------------------

$(function(){
  $("ul li").click(function(){
$(this).find("a").addClass("bianse");
$(this).siblings().find("a").removeClass("bianse");
  });
})
/*你的样式在a标签里面不是在li里面*/

------解决方案--------------------
点击超链接 跳转  不需要用js
你直接在那页面上加class就可。
------解决方案--------------------
引用:
点击超链接 跳转  不需要用js
你直接在那页面上加class就可。

这个正解,你改变当前的也没用,页面是要跳转的
------解决方案--------------------
if(document.href=axxxxxx){
elem.addclass(xxxx)
}
------解决方案--------------------
通过分析url地址得到页面,然后和dom的a比较下href就知道是那个a得到焦点了

<UL id="ulGuider">
  <LI><A class="bianse" href="a.aspx">导航一</A> </LI>
  <LI><A href="b.aspx">导航二</A> </LI>
  <LI><A href="c.aspx">导航三</A> </LI>
</UL>

<style>
a.focus{background:#ff0000;color:#ffffff;}
</style>
<script>
    var pn = location.pathname;
    var as = document.getElementById('ulGuider').getElementsByTagName('a'), find = false;
    for (var i = 0, j = as.length; i < j; i++)
        if (as[i].href.indexOf(pn) != -1) { as[i].className = 'focus'; find = true; break; }
    //if (!find) as[0].className = 'focus';//如果未找到匹配的,需要设置哪个获取焦点可以修改这句
</script>

------解决方案--------------------
var $h = document.URL;
var $match = $h.match(/.*\/(.*\.aspx)$/);
var $m=$match[1];
$('a[href="'+$m+'"]').addClass("bianse");
  相关解决方案