javascript – .listview()在jquery mobile中创建动态列表视图时不是函数错误

我正在尝试在查询facebook api后在
jquery mobile中创建动态列表视图,以检索用户的新闻源.这是我标记的一部分:

markup += '<li><a href=""><img src="https://graph.facebook.com/' + id + '/picture">'+'<h4>' + name + '</h4><p>' + short_post +'....</p></a></li>';

然后我有,

 $(newsfeedposts).append(markup);

$(newsfeedposts).trigger("create");

然后在那之后我打电话给

$(newsfeedposts).listview("refresh");

我得到一个类型错误:TypeError:$(…).listview不是一个函数

我的html div标签就是这个

  <div data-role="content"> <div class ="post">
    <ul data-role="listview"  class="ui-listview" id="newsfeedposts" data-divider-theme="b" data-theme="a" data-overlay-theme="a" data-autodividers="true" data-inset="true">
</ul>
  </div>

如果你确定我做错了什么,请告诉我.这已经花了这么长时间……

最佳答案 你没有以正确的方式使用jQuery-selector.要使用id定位元素,请使用$(‘#element_id’)和类$(‘.element_class’)的元素.因此,您的选择应如下所示.

$('#newsfeedposts').append(markup);

然后

$('#newsfeedposts').listview('refresh');
点赞