强制 jQuery Mobile 重新评估动态插入内容的样式/主题 [英] Forcing jQuery Mobile to re-evaluate styles/theme on dynamically inserted content
问题描述
目标:通过 $.ajax
加载 HTML 内容,将其插入到 DOM 中,让 jQuery Mobile 为其应用主题样式.
Objective: Load HTML content via $.ajax
, insert it into the DOM, have jQuery Mobile apply theme styles to it.
问题:内容被插入但缺少 jQuery Mobile 主题.
Problem: Content gets inserted but lacks jQuery Mobile theming.
代码:
$.ajax({
...
success: function(html) {
$('#container').append(html);
$('#page').page('refresh', true);
}
});
返回的 HTML 包含 data-role
标签,jQM 应该设置这些标签...
The HTML returned includes data-role
tags which jQM should style...
<a data-role="button">Do Something</a>
我没有像应有的那样应用样式,而是收到以下错误:
Instead of applying the styles like it should, I get the following error:
未捕获的异常:没有这样的方法页面小部件实例的刷新"
uncaught exception: no such method 'refresh' for page widget instance
<小时>
以上代码使用http://code.jquery.com/mobile/latest/jquery.mobile.js
导致我出现上述错误消息的类似问题:
Similar questions which brought me to the above error message:
JQM (jQueryMobile) 动态添加的元素未正确显示且未应用 CSS
推荐答案
刚刚得到一个类似问题的答案,尝试使用
Just got an answer to a similar question, try using
.trigger("create")
在将内容添加到的元素上.
on the element that gets the content added to.
参见此处:jQuery Mobile 不应用样式动态添加内容后
这篇关于强制 jQuery Mobile 重新评估动态插入内容的样式/主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!