动态添加内容后jQuery Mobile不应用样式 [英] jQuery Mobile does not apply styles after dynamically adding content

查看:34
本文介绍了动态添加内容后jQuery Mobile不应用样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题出现在几个地方(强制 jQuery Mobile 重新评估动态插入内容的样式/主题)但没有对我有用的答案.

我正在使用 ajax 加载一些内容,并将其插入到 div 中,如下所示:

 $.ajax({网址:../Services/CalendarService.cshtml?service=true",缓存:假,成功:功能(数据){数据 = $.parseJSON(data);var s = $("#user_tmpl").html();var s1 = tmpl(s, 数据);$(#target").html(s1);$(#targetRefresh").page();}});

我尝试在我添加 html 的目标和页面上设置 targetRefresh,但没有成功.已插入内容,但未应用样式.

我也试过

.trigger(增强")

知道该怎么做吗?

插入的html是一堆这样的:

<h3>MyOwner2AA</h3><p>MyDescription</p><p>/日期(1320339836735)/</p><p>MyOwner</p><i></i>

感谢您的帮助

拉西

解决方案

尝试在具有新内容的元素上调用 .trigger("create").

根据 jQuery Mobile 文档,"create 事件适用于增强包含一个或多个小部件的原始标记."

编辑:从 jQuery Mobile 1.4 开始,.trigger('create') 已弃用,您应该使用 .enhanceWithin() 代替.(感谢 John Mc 的提醒.)

I know this questions appear several places (Forcing jQuery Mobile to re-evaluate styles/theme on dynamically inserted content) but not with an answer that is working for me.

I'm loading some content using ajax, and inserting it into a div like this:

       $.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();
            }
        });

I've tried setting the targetRefresh on both the target I'm adding the html to, and on the page, but with no luck. The conent is inserted, but styles not applied.

I've also tried

.trigger("enhance")

Any idea what to do?

The html that inserted are a bunch of these:

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

Thanks for any help

Larsi

解决方案

Try calling .trigger("create") on the element with the new content.

According to the jQuery Mobile docs, "The create event is suited for enhancing raw markup that contains one or more widgets."

EDIT: As of jQuery Mobile 1.4, .trigger('create') is deprecated, and you should use .enhanceWithin() instead. (Thanks to John Mc for the heads-up.)

这篇关于动态添加内容后jQuery Mobile不应用样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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