强制jQuery Mobile重新评估动态插入内容的样式/主题 [英] Forcing jQuery Mobile to re-evaluate styles/theme on dynamically inserted content

查看:99
本文介绍了强制jQuery Mobile重新评估动态插入内容的样式/主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:通过$.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:

使用适当的jQuery Mobile样式持续更新页面

JQM(jQueryMobile)动态添加的元素无法正确显示且未应用CSS

jQuery Mobile-动态创建表单元素

推荐答案

刚刚得到一个类似问题的答案,请尝试使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆