上面例子,打错了一点点
<html>
<head>
 <title></title>
 <>
  test()
 {
  document.write('after click.');
  location.hash='123';
 }
 </>
</head>
<body>
 <div ="test();">click on me!</div>
</body>
</html>

解决方案 »

  1.   

    <html>
    <head>
     <title></title>
     <>
      function test()
     {
      document.write('after click.');
      location.hash='123';
     }
     </>
    </head>
    <body>
     <div ="test();">click on me!</div>
    </body>
    </html>
      

  2.   

    <html>
    <head>
     <title></title>
     <script>
      function test()
     {
      document.write('after click.');
      location.hash='123';
     }
     </script>
    </head>
    <body>
     <div ="test();">click on me!</div>
    </body>
    </html>
      

  3.   

    你是想让页面跳到锚点而不在地址栏显示?
    正常情况是应该显示的。如果不想显示的话,可以用框架然后来改变框架的location。
    我没有测试,如果是你所说IE做了处理不显示是它自己的特殊的处理方法。
      

  4.   

    不是啊,我是想利用document.write();向页面重新绘制HTML,实现前进后退和可刷新,
    想利用location.hash来改变地址栏的显示.
      

  5.   

    /**
    不是啊,我是想利用document.write();向页面重新绘制HTML,实现前进后退和可刷新,
    想利用location.hash来改变地址栏的显示.
    **/直接window.reload()不能满足?;
    或者结合document.referrer//取得上一个页面;
      

  6.   

    /**
    直接window.reload()不能满足?;
    或者结合document.referrer//取得上一个页面;
    **
    没有window.reload()哦,只有location.reload(),但不能解决我的问题哦
      

  7.   

    <html>
    <head>
     <title></title>
     <script>
      function test()
     {
      document.write('after click.');
      location.href=location.href+'#123';
     }
     </script>
    </head>
    <body>
     <div onclick="test();">click on me!</div>
    </body>
    </html>
      

  8.   

    这里还有分
    http://community.csdn.net/Expert/topic/5106/5106260.xml?temp=.2900659
      

  9.   

    http://community.csdn.net/Expert/topic/5059/5059795.xml?temp=.6841852
      

  10.   

    帮你顶
    google了半天没找到解决方案,等高人
      

  11.   

    恩!谢谢楼上的大哥了!我也GOOGLE不到!!
      

  12.   

    <html>
    <head>
     <title></title>
     <script>
      function test()
     {
      document.body.innerHTML = 'after click.';
      location.href='#123';
     }
     </script>
    </head>
    <body>
     <div onclick="test();">click on me!</div>
    </body>
    </html>换一种思维吧,你的 document.write 无非也就是把页面里的所有元素抹去,只剩下白板,那么我使用 document.body.innerHTML 这样的赋值也可以达到你的目的,当然要做得完美点的话,把 body 的一些样式也改成初始状态最好了。另附:在FF之类的浏览器里用了 document.write(); 之后一定要记着用 document.close(); 否则状态栏里会处于一直加载页面的状态的。
      

  13.   

    meizz(梅花雪)大哥,我就是因为想实现浏览器前进后退和可刷新才用document.write()的,
    如果使用document.body.innerHTML的话,我按F5刷新一下,就又变会原来那样了..
      

  14.   

    <html>
    <head>
    <title></title>
    <script>
    function test()
    {
    location.hash='123';
    document.write('after click.');
    document.close();
    }
    </script>
    </head>
    <body>
    <div onclick="test();">click on me!</div>
    </body>
    </html>