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

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

问题描述

我知道这个问题出现几个地方(<一href="http://stackoverflow.com/questions/6297470/forcing-jquery-mobile-to-re-evaluate-styles-theme-on-dynamically-inserted-conten">Forcing jQuery Mobile的对动态插入内容重新评估风格/主题),但不与正在为我一个答案。

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.

我用ajax加载一些内容,并将其插入这样一个div:

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

我已经尝试设置targetRefresh两个我加入HTML到目标,并在页面上,但没有运气。所述conent被插入,但不能应用的样式。

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.

我也试过

.trigger("enhance")

任何想法,该怎么办?

Any idea what to do?

这是插入的HTML是一帮这些:

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

推荐答案

尝试调用 .trigger(创造)与新内容的元素。

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

按照 jQuery Mobile的文档创建事件是适合于提高原始标记包含一个或多个部件。

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

修改:作为jQuery Mobile的1.4, .trigger('创建')is德precated ,你应该使用 .enhanceWithin()代替。 (感谢约翰·麦当劳的对决。)

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天全站免登陆