<script language="javascript" type="text/javascript">
thisURL = document.URL;
host=thisURL.substring(0,thisURL.indexOf("/",7)+1);
thisHREF = document.location.href; 
tmpPage = thisHREF.split( "/" ); 
thisPage = tmpPage[tmpPage.length-1];
thisPage=thisPage.substring(0,thisPage.indexOf("."));
if(thisPage.indexOf("?")>-1){
page=thisPage.substring(0,thisPage.indexOf("?"));
}else{
page=thisPage;
}
//document.write(document.getElementById("index").innerHTML);
if(page!=""){
document.getElementById(page).addClass="current";
}else{
document.getElementById("index").addClass="current";
}
</script>
<div id="templatemo_header">
         <div id="templatemo_logo">
             <h1>YIYANG18 dress</h1>
                <h2>make solution</h2>
  </div>
            <div id="templatemo_menu">
<ul>
<li id="index"><a href="index.php"><b>首页</b></a></li>
<li id="solution"><a href="solution.php"><b>制作方案</b></a></li>
    <li id="newsT"><a href="newsT.php"><b>新款T恤</b></a></li>
<li id="class"><a href="class.php"><b>分类查询</b></a></li>
                    <li id="guide"><a href="guide.php"><b>订作指南</b></a></li>
    <li id="about"><a href="about.php"><b>关于我们</b></a></li>
</ul>
  </div>
</div>
页面跳转后,样式添加不上。大家帮看看。

解决方案 »

  1.   


    <script language="javascript" type="text/javascript">
       window.onload = function(){//写在onload里,否则找不到对象,肯定加不上。
        thisURL = document.URL;
        host=thisURL.substring(0,thisURL.indexOf("/",7)+1);
        thisHREF = document.location.href; 
        tmpPage = thisHREF.split( "/" ); 
        thisPage = tmpPage[tmpPage.length-1];
        thisPage=thisPage.substring(0,thisPage.indexOf("."));
        if(thisPage.indexOf("?")>-1){
            page=thisPage.substring(0,thisPage.indexOf("?"));
        }else{
            page=thisPage;
        }
        //document.write(document.getElementById("index").innerHTML);
        if(page!=""){
            document.getElementById(page).addClass="current";
        }else{
            document.getElementById("index").addClass="current";//一般这样写:style.className='current';
        }
    }
    </script>
      

  2.   

    我是获取跳转到页面文件名作ID,跟转过去将这个ID样式改掉得到的page值是对的。但是修改不了样式。
      

  3.   

    不可以呢.这是我的top.php文件.查看源文件里也没见添加上
      

  4.   

    你的JS是出现在你要修改的html元素之后吗? 如果是之前 是找不到的
      

  5.   

    要在页面id为page的对象加载完成后调用。
     document.getElementById(page).className="current";
      

  6.   

    <script language="javascript" type="text/javascript">
     window.onload = function(){
    thisURL = document.URL;
    host=thisURL.substring(0,thisURL.indexOf("/",7)+1);
    thisHREF = document.location.href; 
    tmpPage = thisHREF.split( "/" ); 
    thisPage = tmpPage[tmpPage.length-1];
    thisPage=thisPage.substring(0,thisPage.indexOf("."));
    if(thisPage.indexOf("?")>-1){
    page=thisPage.substring(0,thisPage.indexOf("?"));
    }else{
    page=thisPage;
    }
    //document.write(document.getElementById("index").innerHTML);
    if(page!=""){
    document.getElementById(page).className="current";
    }else{
    document.getElementById("index").className="current";
    }
    }
    </script>