jQuery的样式动态创建不应用 [英] jquery styles not applied in dynamically creation

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

问题描述

我创建了jQuery Mobile的可折叠列表视图。它这一个为动态。如果我创建了HTML code可折叠,其显示效果细腻。同样一个我试图为动态,那么样式不适用。

I created collapsible listview in jquery mobile. It this one as dynamically. If I created collapsible in html code, it display fine. The same one I tried as dynamically, then the styles are not applied.

code在HTML网页:

Code in Html page:

<div data-role="collapsible">
                    <h2>Bucks County<br>BU</h2>
                    <ul data-role="listview">
                        <li><a href="index.html">Location </a></li>
                    </ul>
            </div>

code jQuery中:

Code in Jquery:

$("#lsititems").append('<div data-role="collapsible">'+
                    '<h2>'+data[0].SiteName+'<br>'+data[0].SiteCode+'</h2>'+
                    '<ul data-role="listview">'+
                    '<li>'+'<a href="index.html">'+'Location'+'</a>'+'</li>'+
                    '</ul>'+
                    '</div>') 

我想这其中也:

$("#lsititems").append("<div data-role='collapsible'>"+
                                "<h2>"+data[1].SiteName+"<br>"+data[1].SiteCode +"</h2>"+
                                "<ul data-role='listview'>"+
                                "<li>"+"<a href='index.html'>"+"Location"+"</a>"+"</li>"+
                                "</ul>"+
                                "</div>")  

O / P:

从上面code,从HTML创建第一个,第二个和第三,从动态jQuery中创建的。什么是错误的,我code ..请帮助我..
在此先感谢...

From above code, first one created from Html, 2nd and 3rd created from dynamically in jquery. What's wrong in my code.. please help me.. Thanks in advance...

推荐答案

在jQuery Mobile的,当您添加内容动态需要初始化的内容,或者如果您要添加的内容(例如将项目添加到列表视图),您需要刷新内容。

In jQuery mobile when you add content dynamically you need to initialize the content, or if you are adding content (for example adding items to a listview) you would need to refresh the content.

如果您有需要初始化你可以触发多个项目创建活动在页面上的初始化所有的人。通常最好在 pageshow 事件这样做。

If you have several items that need to be initialized you can just trigger the create event on the page to initialize all of them. Often its best to do so in the pageshow event.

例如

$("#mypage").on('pageshow', function () {
   $(this).trigger("create");
});

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

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