强制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包含jQM应该设置样式的data-role
标签...
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屋!