想实现当t1可视时链接为ddd.html ,当t2可视时链接为ccc.html ,下面的写法有什么错误呢?<a href="javascript:if(t1.style.display=='block') location.href='ddd.html' else if(t2.style.display=='block') location.href='ccc.html'" >更多 &gt;&gt;</a>

解决方案 »

  1.   

    <a href="" onmouseover="if(t1.style.display=='block') this.href='ddd.html'; else if(t2.style.display=='block') this.href='ccc.html';" >更多 &gt;&gt;</a>location.href是指当前页地址,对其赋值就会实现页面的跳转
    location是没有的,应该用window.location楼主的方法缺了一个逗号,才会导致运行错误
    <a href="javascript:if(t1.style.display=='block') location.href='ddd.html' ;else if(t2.style.display=='block') location.href='ccc.html'" >更多 &gt;&gt;</a>
      

  2.   

    二位的方法都尝试过了,this.href 当点击是无反应,location.href还是出现运行错误,错误提示为没有权限!
      

  3.   

    问题并没有出在链接上,location.href,检查一下你t1,t2这两个对象是不是有问题
      

  4.   

    但是我把location.href='ccc.html'改为“alert();”测试一下,是没有问题的,这说明t1和t2是没有问题的!
      

  5.   

    try following code:top.main.location.href='ddd.html'
    or
    top.preview.location.href='ddd.html'
      

  6.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <script>
    function show()
    {
    var span = document.getElementById("2");
    if(span.style.display == "none")
    {
    var a = document.getElementById("1");
    alert(a.href);
    }
    else
    {

    var a = document.getElementById("1");
    a.href="http://www.google.com";

    }
    }
      </script>
     </HEAD> <BODY onload="show();">
    <a href="http://www.baidu.com" id="1">dong</a>  
    <span style="display:block" id="2">dddd</span>
     </BODY>
    </HTML>