Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 即使取消刷新,Internet explorer也会丢失DOM更改_Javascript_Jquery_Html_Internet Explorer_Dom - Fatal编程技术网

Javascript 即使取消刷新,Internet explorer也会丢失DOM更改

Javascript 即使取消刷新,Internet explorer也会丢失DOM更改,javascript,jquery,html,internet-explorer,dom,Javascript,Jquery,Html,Internet Explorer,Dom,我有一个页面,里面有一些帖子数据(来自上一个表单提交)。 此外,我已经在这个页面中更改了DOM(使用jQuery) 当我单击F5时,FF和Internet Explorer都会显示关于重新发送post数据的警告。到目前为止没有什么意外 但当我在弹出窗口中选择“取消”时,即会丢失我对DOM所做的所有更改!另一方面,在FF中发生的事情正是我所期望的:什么都没有 这是IE的已知问题吗? 这种行为有充分的理由吗?(为什么要取消呢?) 这是可以避免的吗 如果人们想了解我的意思,这个测试页面应该: <

我有一个页面,里面有一些帖子数据(来自上一个表单提交)。 此外,我已经在这个页面中更改了DOM(使用jQuery)

当我单击F5时,FF和Internet Explorer都会显示关于重新发送post数据的警告。到目前为止没有什么意外

但当我在弹出窗口中选择“取消”时,即会丢失我对DOM所做的所有更改!另一方面,在FF中发生的事情正是我所期望的:什么都没有

这是IE的已知问题吗? 这种行为有充分的理由吗?(为什么要取消呢?) 这是可以避免的吗

如果人们想了解我的意思,这个测试页面应该:

<!DOCTYPE html>
<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $('#changeColor').click(
                    function(){
                        $('#container').css('background-color', 'blue');
                    }
                );
            });
        </script>
    </head>
    <body>
    <div>
    <p>To see the behaviour that is different in IE versus FF:</p>
    <ul>
        <li>Put something in the textbox and press Submit, just to have a post value.</li>
        <li>Press the "Make blue" button.</li>
        <li>Press F5.</li>
        <li>Click Cancel in the popup.</li>
    </ul>
    </div>
    <div id="container">
    <form method="post">
        <input name="test" type="text">
        <input type="submit" value="Submit">
    </form>
    <button id="changeColor">Make blue</button>
    </div>
    </body>
</html>

$(函数(){
$(“#更改颜色”)。单击(
函数(){
$('#container').css('background-color','blue');
}
);
});
要了解IE与FF的不同行为:

  • 在文本框中输入一些内容,然后按Submit,就可以得到一个post值
  • 按下“蓝色”按钮
  • 按F5
  • 在弹出窗口中单击取消
变蓝
IE可能会在不发送请求的情况下重新加载页面,但新页面的背景不是蓝色的。开发工具中发生了什么?尝试在脚本中放入log语句,我敢打赌它会重新执行。@Bergi你说得对,脚本会再次执行。是的,蓝色背景消失了,因为很明显(缓存的副本?)原始页面被重新加载。但是为什么呢?