1

这是某种方式。我通常使用 jquery 的 load 将页面 A 中的内容加载到页面 B 中,因此将 div 的内容加载到自身中以便刷新它没有多大意义。解决方案是什么?

$('#A').load('pageX.php #A');

请注意,两个 #A 都在 pageX 上,使其成为相同的 #A

在“加载”之后,这以某种方式干扰了 JavaScript,我不知道为什么。

所以这些只是刷新一个div。

4

2 回答 2

0

必须在 html 文档中具有id唯一性,否则您最终将获得 JavaScript 的预期结果。

在您的情况下,您需要删除重复项id's

像这样的东西

$('#A').load('pageX.php #B');

或者这将起作用:

$('#B').load('pageX.php #A');
于 2013-10-18T14:01:30.327 回答
0

因为有人来问这个问题,如果我现在再做一次,我会这样做。

HTML

<html>
<body>
    <div class="divToRefresh"></div>
</body>
</html>

JavaScript(JQuery)

  <script>
$(document).ready(function(e) {
    $.refreshDiv = function(arg){
        var d = {someVariable_you_can_send:arg}
        $.ajax({
            url:'url_to_div_content',
            data:d,
            type:"POST"}).done(function(result){
                $('.divToRefresh').html(result);    
            });     
    };
    //////////call this for the first time//////////
    $.refreshDiv('some value');
    //////////////////////////// and then refresh it after a certain interval if you need to
    window.setInterval(function(){
        $.refreshDiv('some value');
    }, 1000*60*60*60);

});
</script>
于 2015-10-09T15:46:40.077 回答