我要实现类似这页面 http://daohang.google.cn/  名站导航下边的字母,被点击后,背景变为白色。下边是我做的JS,但页面在刷新后,发现被点文字的背景就变一下白色就又回到原来那样了。请指教function onWord(val)
{
    var url="?word="+val;
    location.href=url;

    str1=url.split("=");
    if(str1[1]==val)
    {
 return document.getElementById(val).className="css";
    }

    
}<span  class="" id="a"><a href="#" onclick="onWord('a')">a9999</a></span> .css{background-color:#ffffff;border:1;cursor:hand;} 

解决方案 »

  1.   

    function onWord(val) 

        var url="?word="+val; 
        location.href=url; 

    document.onload=function (){
        var url = window.location.href;
        str1=url.split("="); 
        if(str1[1]==val) 
        { 
            document.getElementById(val).className="css"; 
        } 
    }
      

  2.   

    二楼的,这<span  class="" id="a"> <a href="#" onclick="onWord('a')">a9999 </a> </span> 
    里边还这么写吗? 刚测试了没反映
      

  3.   

    lz,俺在1楼^_^是的,还是那么写没反应
    var url = window.location.href;
    alert(url);//看看是什么?
      

  4.   


    url打印出来是:   ?word=a;    
      

  5.   

    代码有点问题,不好意思,lz你再试试
    document.onload=function (){ 
        var url = window.location.href; 
        str1=url.split("="); 
        document.getElementById(str1[1]).className="css"; 
    }
      

  6.   

    这个函数没调用起来:document.onload=function (){ 
        var url = window.location.href; 
        str1=url.split("="); 
        document.getElementById(str1[1]).className="css"; 
    alert(url);//这个测试都打印不出来,不弹出
    }
      

  7.   

    刚刚不是可以打印出来吗?怎么现在又不可以了呢?
    改成
    window.onload=function (){ 
        var url = window.location.href; 
        str1=url.split("="); 
        document.getElementById(str1[1]).className="css"; 
    alert(url);//这个测试都打印不出来,不弹出 
    }