<ul>
<li><a id="menu1" href="#">首页</a></li>
<li><a id="menu2" href="#">产品介绍</a></li>
</ul>字体默认为黑色怎样在点击“首页”后,“首页”变为白色,点击“产品介绍”后,“产品介绍”变为白色,“首页”变回黑色
求简单的代码!!麻烦大家了!!

解决方案 »

  1.   

    点击后,页面会重新加载!
    应该在 onload 中实现!你href 值是相同的,只能通过cookie 来实现()当然,实际上 href 是不会相同的。所以可以感觉 地址栏 url 和 href 比较!
    来设置对应的颜色
      

  2.   

    http://topic.csdn.net/u/20110322/09/67365703-cbc0-4ca2-bc75-a4014664ab7e.html
      

  3.   

      可以用css样式来设定。
      

  4.   

    <style type="text/css">
    body{background-color:#336600}
    a{color:#000}
    </style>
    <body>
    <ul>
    <li><a id="menu1" href="#" onclick="kkk(this)">首页</a></li>
    <li><a id="menu2" href="#" onclick="kkk(this)">产品介绍</a></li>
    </ul>
    <script type="text/javascript">
    <!--
    function kkk(obj){
    if(this.oldObj!=undefined){
    this.oldObj.style.color = "#000";
    }
    this.oldObj = obj;
    obj.style.color = "#fff"
    }
    //-->
    </script>
      

  5.   

    你再试试看,我在ie和ff下都测试ok
      

  6.   

    first.htm 和 second.htm代码一样,如下:
    <html>
    <head>
    <style>
    a:link,
    a:active,
    a:hover,
    a:visited{
    text-decoration: none;
    }
    </style>
    <script>
    var linkList = [["fPage","first.htm"],["sPage","second.htm"]];
    function judge()
    {
    for(i=0;i<linkList.length;i++)
    {
    if(linkList[i][1].toUpperCase() == GetCurrentPage().toUpperCase())
    {
    document.getElementById(linkList[i][0]).style.color = "red";
    }
    else
    document.getElementById(linkList[i][0]).style.color = "";
    }
    }window.onload = function(){judge();};function GetCurrentPage() {
      var u = document.location.href;
      var i = u.indexOf('?');
      if (i > 0)
      u = u.substring(0, u.indexOf('?'));
      var info = u.split('/');
      var page_info = info[info.length - 1].split('?');
      return page_info[0];
    }
    </script>
    </head>
    <body>
    <a href="first.htm" id="fPage">首页</a>
    <a href="second.htm" id="sPage">第二页</a>
    </body>
    </html>
      

  7.   

    8楼的朋友代码太长了,我希望能用简单点的代码,还有我是用ifame来显示点击的网页的