javascript – 如何在jquery(移动)中刷新DIV?

前端之家收集整理的这篇文章主要介绍了javascript – 如何在jquery(移动)中刷新DIV?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
更新:抱歉,我不小心将data-dom-cache =“true”行复制到了我的content-div中.似乎非常符合逻辑,即应用程序是从dom而不是新内容加载的!我把它改成了假,现在它完美无缺.

谢谢.

我有一个动态生成的列表.如果有人单击列表中的条目,则会将用户重定向到加载数据的新页面(动态).加载的数据取决于用户单击的列表条目.

当应用程序第一次加载时,一切正常.但是当用户点击另一个列表条目时,相同的数据表示为第一次运行时.

我已经玩过jQuery中的.empty()函数(清除div并附加新数据),但它不起作用.

编辑:

我的headlines.html文件如下所示:

<div id="content>
  <div id="headlineslist">
    <ul data-role="listview" data-theme="c" id="headlineslist">
    </ul>
  </div>
</div>
<script>
  $(document).ready(function() {
    HeadlinesLoad();
  });
</script>

这是Javascript文件

function HeadlinesLoad() {
  $.ajax({
    type: "POST",url: "headlines_getter.PHP",dataType: 'json',cache: false,success: function(data1) {
      $.each(data1,function(i,currentObj) {
        $('ul#headlineslist').append('<li data-role="list-divider" 
class=​"ui-li ui-li-divider ui-bar-b">​' + currentObj.main + '</li>​').listview('refresh');
        $.each(currentObj.sub,function (j,currentSub) {
          $('ul#headlineslist').append('<li>
<a href="headlinesclicked_temp.html" onclick="headlineID(' + currentSub.sid + ')">' + currentSub.name + '</a></li>').listview('refresh');
        });
      });
    }
  });
}

function headlineID(hID) {
  window.localStorage.setItem("headlineID",hID);
}

function onHeadlinesLoad() {
  var hID = window.localStorage.getItem("headlineID");
  window.localStorage.removeItem("headlineID");
  window.localStorage.clear();
  $.ajax({
    url: "headlinesclicked_getter.PHP?hID=" + hID,success: function(html) {
      if(html){
        $("#headlineshome").empty();
        $("#headlineshome").html(html);
      }
    }
  });
}

以下是放在HTML文件中的片段,其中应显示数据(并在用户执行的每次新点击时刷新):

<div data-role="content" id="headlineshome"></div>
<script>
  $(document).ready(function() {
    onHeadlinesLoad();
  });
</script>

我不知道为什么它不起作用,所以我请求你帮忙.

提前致谢.

最好的问候,约翰.

解决方法

一旦你使用jQuery mobile更新你的列表,考虑触发“创建”事件,但是这已经过时了,所以请使用
.page()

在你的名单上这样:

$('ul#headlineslist').page();
原文链接:https://www.f2er.com/jquery/157203.html

猜你在找的jQuery相关文章