jQuery自动刷新div搞乱了 [英] jQuery Auto refresh div messing up

查看:98
本文介绍了jQuery自动刷新div搞乱了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以自动刷新页面上的某个div(我从这里的另一篇文章中获得)

I have a script that auto-refreshes a certain div on the page (That I got from another post on here)

<script type="text/javascript">
    var auto_refresh = setInterval(
    function(){
        $('#refresh').load('index.php?_=' +Math.random()).fadeIn("slow");
    }, 10000); // refresh every 10000 milliseconds
</script>
...............
<div id="refresh">
  <!-- Some PHP Code -->
</div>

然而,当它刷新时,我将整个html文档放到div中。像这样:

This refreshes, however when it does, I takes the entire html document and puts it into the div. Like this:

正如你所看到的那样,刷新的div(红色标记的那个)正在让身体冲向它。任何想法???

As you can see, the refreshed div (the one marked in red) is getting the body shouved into it. Any ideas???

推荐答案

您正在将整个页面加载到div。
修改代码以仅使用获取文档的一部分:

You are loading entire page to the div. Modify the code to use only part of the document that is fetched:

    <script type="text/javascript">
        var auto_refresh = setInterval(
        function(){
            $('#refresh').empty();
            $('#refresh').load('index.php?_=' +Math.random()+' #refresh').fadeIn("slow");
        }, 10000); // refresh every 10000 milliseconds
    </script>

这篇关于jQuery自动刷新div搞乱了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆