<script>
function test(obj) {
var hour = (new Date).getHours();
if (hour>=7 && hour<18)
obj.href="a.html";
else
obj.href="b.html";
}
</script>
<a href="#" onclick="test(this)">test</a>

解决方案 »

  1.   

    -_-bbbb<script>
    function test(obj) {
    var hour = (new Date).getHours();
    if (hour>=7 && hour<=18)
    obj.href="a.html";
    else
    obj.href="b.html";
    }
    </script>
    <a href="#" onclick="test(this)">test</a>
      

  2.   

    在页面上判断当前时间范围:
    <script>
    var nh = new Date().getHours();
    switch(nh){
    case 1:window.location="http://www.sina.com.cn";break;
    case 2:window.location="http://www.sohu.com";break;
    case 3:window.location="http://www.163.com";break;
    case 4:window.location="http://www.csdn.net";break;
    //case 其他的小时;
    default:window.location="http://www.jxxg.com";break;
    }
    </script>
      

  3.   

    JF  <script type="text/javascript">
      <!--
    function automaticRedirectByTime(){
       var currentTime = new Date();
       var numHour = currentTime.getHours();   var strTargetPage = "b.html";
       if (numHour>=7 && numHour<18)
       {
           strTargetPage = "a.html";
       }   if (document.location.href.indexOf(strTargetPage) == -1)
       {
           document.location.href = strTargetPage;
       }}
      //-->
      </script>
     </head>
     <body onload="automaticRedirectByTime();">
     </body>