我有index.htm和index2.htm两个页面。index上有一个按钮remove text,可以删除页面上的元素内容然后跳转到index2,然后点击浏览器的后退按钮,index上被删除的元素又重新出现,我的问题是如何删除一个元素,可以让浏览器后退的时候也看不到这个被删元素?谢谢!以下是index.htm代码:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js"></script>
<title>test</title>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$('#content').html("<p>aaaaaabbbaaaaaa</p>");
});function hideText()
{
    $('#content').remove();
    window.location.href="index2.htm";
}</script>
</head>
<body>
<div id="content">
</div>
<div>
<input id="hide" type="button" value="remove text" onclick="hideText();"/>
</div>
</body>
</html>
以下是index2.htm代码<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body>
<div id="content">
page2
</div>
</body>
</html>

解决方案 »

  1.   

    这个只有设置cookie了,你可以搜索一下jquery.cookie。
    即点击按钮后,保存一个cookie值,然后在index2.htm的head部分验证这个cookie是否存在,如果存在,
    $('#content').remove();
      

  2.   

    我晕。。后退相当于重新刷新页面,当然会重现了。要么服务端输出页面,要么把删除的行为写到cookie里面再重复做。
      

  3.   


    不同浏览器对于后退的实现不太一样,IE是会执行onload,而ff,safari等浏览器不会执行,而是保持原样。
      

  4.   


    “然后在index2.htm的head部分验证这个cookie是否存在”,应该是index1.thm的head部分验证这个cookie是否存在吧?
      

  5.   

    <!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">
    function test(){
    var a=document.getElementById("test");
    if(a){
    var p=a.parentNode;
    p.removeChild(a);
    document.cookie="removes=true;";
    }
    window.location.href="http://www.baidu.com";
    }
    function init(){
    var a=document.cookie;
    var b=a.indexOf("removes=");
    var c=a.indexOf(";",b);
    if(c==-1){
    c=a.length;
    }
    var d=a.substring(b+8,c);
    if(d=="true"){
    var a=document.getElementById("test");
    var p=a.parentNode;
    p.removeChild(a);
    }
    }
    window.onload=init;
    </script>
    </head><body>
    <div id="test" style="width:400px; height:400px; background-color:#0F0"></div>
    <input type="button" value="test" onclick="test()">
    </body>
    </html>
    这样试试
      

  6.   

    2个页面你都可以设置一下。这样你不论前进和后退,都可以记住状态隐藏DIV。
      

  7.   

    火狐试了下貌似也可以  你在遨游下输出cookie值看看