目标: 通过加载HTML内容$.ajax,将其插入DOM,让jQuery Mobile应用主题样式.
问题: 内容被插入但缺少jQuery Mobile主题.
码:
$.ajax({
...
success: function(html) {
$('#container').append(html);
$('#page').page('refresh', true);
}
});
Run Code Online (Sandbox Code Playgroud)
返回的HTML包含data-rolejQM应该样式的标签......
<a data-role="button">Do Something</a>
Run Code Online (Sandbox Code Playgroud)
我没有应用它应该的样式,而是出现以下错误:
未捕获的异常:没有这样的方法'刷新'页面小部件实例
以上代码测试使用 http://code.jquery.com/mobile/latest/jquery.mobile.js
类似的问题让我收到上述错误信息:
我知道这些问题出现在几个地方(迫使jQuery Mobile重新评估动态插入内容的样式/主题)但不是一个对我有用的答案.
我正在使用ajax加载一些内容,并将其插入到div中,如下所示:
$.ajax({
url: "../Services/CalendarService.cshtml?service=true",
cache: false,
success: function (data) {
data = $.parseJSON(data);
var s = $("#user_tmpl").html();
var s1 = tmpl(s, data);
$("#target").html(s1);
$("#targetRefresh").page();
}
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试在目标上设置targetRefresh我将html添加到页面上,但没有运气.插入了conent,但未应用样式.
我也试过了
.trigger("enhance")
Run Code Online (Sandbox Code Playgroud)
知道该怎么办?
插入的html是一堆这样的:
<div data-theme="e" data-collapsed="true" data-role="collapsible"> <h3>MyOwner2AA</h3> <p>MyDescription</p> <p>/Date(1320339836735)/</p> <p>MyOwner</p> <i></i> </div>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
Larsi