动态绑定的导航条的问题 默认一个背景图片,鼠标移动上去变色,点击也变色其他的变回默认我现在写的方法是
   #leftMune ul li a:link
        {
            background: url(../../AdvertisementImg/DingZhiSiYouYun/Button2.jpg);
        }
        #leftMune ul li a:hover
        {
            color: White;
            background: url(../../AdvertisementImg/DingZhiSiYouYun/Button1.jpg);
            font-weight: bold;
        }
        #leftMune ul li a:active
        {
            color: White;
            background: url(../../AdvertisementImg/DingZhiSiYouYun/Button1.jpg);
            font-weight: bold;
        }这样的方法可是实现功能 但是问题是 当点击一个a变迁 设定其背景后,,鼠标移开点击其他地方, 那刚刚设置的颜色
又变了回来 改怎么解决这一问题

解决方案 »

  1.   

    可能是“回发”引起的初始化,需要记下当前的状态,回发时载入上次的状态。
    可以把状态存入cookies或者隐藏域,页面加载时用js取出状态给超链接样式。
      

  2.   

     好了 分享并结贴了
         <style type="text/css">
     
            #news
            {
                background: url(../../AdvertisementImg/DingZhiSiYouYun/Button1.jpg);
                color:White; font-weight:bold
            }
            #news1
            {
                background: url(../../AdvertisementImg/DingZhiSiYouYun/Button2.jpg);
            }
        </style>    <script type="text/javascript">
        
        $(document).ready(function () {
            $flag = $("#content ul li a")  //获取导航栏中所有的a标签
            $flag.first().attr("id", "news");//获取导航栏中第一个a标签 并切给予设置一个id=new
            $("#content ul li a:not([id='news'])").attr("id","news1");//获取导航栏中id!=new的所有标签 并切给予设置一个id=new1
            $flag.click(function () {
                $("#content ul li a:not(attr='click')").attr("id","news1");//点击一个标签的时侯,就设置这个标签的id为new 把其他的设置为new1 从而达到变换的效果
                $(this).attr("id", "news")
            }
            );
        }) 
        </script>
    html略   就是一些 li 里面套点a标签
    效果就是 点击一个a标签 背景色变为指定的,其他没被点击的还原默认颜色