日期:2014-05-16  浏览次数:20348 次

JavaScript跳转链接问题
有两个页面
a.html
a.html下面有三个a标签
<a href="">任务流程</a><a href="">常见问题</a><a href="">相关链接</a>

a.html页面下
<a href="">任务流程</a>内容(这个是显示的状态)
<a href="">常见问题</a>内容(这个是隐藏的状态)
<a href="">相关链接</a>内容(这个是隐藏的状态)

我想实现的是在a.html中点击任务流程之后跳转的b.html页面中,任务流程和对应的内容是显示的,其他隐藏
我想实现的是在a.html中点击常见问题之后跳转的b.html页面中,常见问题和对应的内容是显示的,其他隐藏
------解决方案--------------------
地址栏传递参数,然后再跳转到的页面判断即可 ?type=1  根据参数判断哪些显示,那么隐藏
------解决方案--------------------
a.html

<html>
<head>
 
</head>
<body>
<a href="b.html?index=1">任务流程</a>
<a href="b.html?index=2">常见问题</a>
<a href="b.html?index=3">相关链接</a>



<script type="text/javascript">
 
  </script>
</body>
</html>

b.html
<!DOCTYPE html PUBliC "-//W3C//dtD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/dtD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>测试</title>

  <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

  <script type="text/javascript">

  window.onload = function(){
    var url = location.search; //获取url中"?"符后的字串
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      var index = str.split("=")[1] - 1;
      
        document.getElementsByTagName('a')[index].style.display = 'block';
      
    }
  }
  </script>

<body>
<a href="b.html?index=1" style="display:none">任务流程</a>
<a href="b.html?index=2" style="display:none">常见问题</a>
<a href="b.html?index=3" style="display:none">相关链接</a>

</body>
</html>

------解决方案--------------------
var hash; 
hash=(!window.location.hash)?"#search":window.location.hash; 
window.location.hash=hash; 
  //调整地址栏地址,使前进、后退按钮能使用 
switch(hash){   
case "1":  
   //显示任务流程
    break;    
case "2":    
   //常见问题
    break;    
case "3":  
   //相关链接
    break;    
     
}