【问题标题】:Basic jquery mobile styling is not applied to dynamically added list items基本 jquery 移动样式不适用于动态添加的列表项
【发布时间】:2013-11-11 10:12:42
【问题描述】:

我想使用 jquery-mobile 动态创建列表。我有 ul

<ul data-role="listview" id="bList"></ul>

我正在使用模板向其中动态添加列表项:

<li id="someid" data-wrapperels="div" data-shadow="false" data-icon="false">
    <a href="#">some text</a>
</li>

li 附加到我正在调用的列表之后

$('#bList').listview('refresh');

这将创建列表并显示出来。但未显示li 的默认 jquery 移动样式。它将只读列表显示为http://jquerymobile.com/demos/1.2.1/docs/lists/lists-readonly.html

尽管指定了data-wrapperels="div",但内容也不包含在 div 中。我希望列表显示为 http://jquerymobile.com/demos/1.2.1/docs/lists/lists-ul.html

我也尝试过显示静态列表,但仍然没有应用样式。 请帮忙。谢谢。

【问题讨论】:

  • 你也动态添加ul
  • 没有。 'ul' 已经存在。我只是动态地附加'li'。
  • 这正常工作jsfiddle.net/Palestinian/s423A你如何/何时动态追加项目?此外,在head 中显示库链接。您正在使用的 jQuery 和 jQuery Mobile 版本。
  • @sonam 请加个小提琴
  • 如果您使用的是 JQM 1.4,请使用 .enhanceWithin() 而不是 .listview()。至少在 JQM 1.4 中使用 jquery 1.9.x

标签: jquery jquery-mobile


【解决方案1】:
$('#bList').listview('refresh');
$('#bList').trigger("create");

【讨论】:

  • 先触发再刷新 $('#bList').trigger("create"); $('#bList').listview('refresh');
猜你喜欢
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多