上面例子,打错了一点点
<html>
<head>
<title></title>
<>
test()
{
document.write('after click.');
location.hash='123';
}
</>
</head>
<body>
<div ="test();">click on me!</div>
</body>
</html>
<html>
<head>
<title></title>
<>
test()
{
document.write('after click.');
location.hash='123';
}
</>
</head>
<body>
<div ="test();">click on me!</div>
</body>
</html>
<head>
<title></title>
<>
function test()
{
document.write('after click.');
location.hash='123';
}
</>
</head>
<body>
<div ="test();">click on me!</div>
</body>
</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>
正常情况是应该显示的。如果不想显示的话,可以用框架然后来改变框架的location。
我没有测试,如果是你所说IE做了处理不显示是它自己的特殊的处理方法。
想利用location.hash来改变地址栏的显示.
不是啊,我是想利用document.write();向页面重新绘制HTML,实现前进后退和可刷新,
想利用location.hash来改变地址栏的显示.
**/直接window.reload()不能满足?;
或者结合document.referrer//取得上一个页面;
直接window.reload()不能满足?;
或者结合document.referrer//取得上一个页面;
**
没有window.reload()哦,只有location.reload(),但不能解决我的问题哦
<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>
http://community.csdn.net/Expert/topic/5106/5106260.xml?temp=.2900659
google了半天没找到解决方案,等高人
<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(); 否则状态栏里会处于一直加载页面的状态的。
如果使用document.body.innerHTML的话,我按F5刷新一下,就又变会原来那样了..
<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>