JQuery 移动 ->.append() 删除 CSS? [英] JQuery mobile -> .append() removes CSS?

查看:22
本文介绍了JQuery 移动 ->.append() 删除 CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将项目附加到我的列表时,jquery mobile 的完整样式消失了......不知道如何解决这个问题?

这是目前有效的:当不附加列表项时,所有样式都可以.

<div class="ui-block-a" id="blockaid"><ul id="leftnav" data-role="listview" data-theme="g" data-filter="true" ><li><a href="index.html"><img src="images/bb.jpg"/><h3>名字 姓氏</h3><p>123456789</p></a></li>

<div class="ui-block-b">...

但是如果我开始使用从其他地方读取数据,所有样式都消失了:

 $(document).ready(function() {$.ajax({网址:'test.xml',数据类型:xml",成功:解析,错误:函数(xhr,ajaxOptions,throwedError){警报(xhr.status);警报(抛出错误);}});函数解析(文档){$(document).find("Details").each(function(){$("#leftnav").append('
  • '+ ''+ '<img src="images/album-xx.jpg"/>'+'<h3>'+ $(this).find('Name').text() + '</h3>'+'<p>'+ $(this).find('Number').text() + '</p>'+'</a>'+ '</li>');});}});
  • 怎么了?

    谢谢!

    好吧,要在新元素上触发自动样式,使用 .trigger("create") 应该可以完成这项工作.

    见:是否有可能使用 jQuery Mobile 即时创建元素?

    http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/pages/page-scripting.html

    $('#leftnav').listview('refresh') 是您要寻找的东西,而不是创建的东西.

    参见:http://api.jquerymobile.com/listview/#method-refresh

    when appending items to my list, the complete style of jquery mobile is gone... dont know how to fix this?

    This is currently working: when not appending the list-items, all styles are fine.

    <div class="ui-grid-a">
                    <div class="ui-block-a" id="blockaid">
                        <ul id="leftnav" data-role="listview" data-theme="g" data-filter="true" >
    
                            <li><a href="index.html">
                                    <img src="images/bb.jpg" />
                                    <h3>Firstname Lastname</h3>
                                    <p>123456789</p>
                                </a></li>
                        </ul>
    
                    </div>
    
                   <div class="ui-block-b">
                    ...
    

    But if I start using to read the data from else where, all styles are gone:

            $(document).ready(function() {
    
                $.ajax({
                    url: 'test.xml', 
                    dataType: "xml",
                    success : parse,
                    error : function (xhr, ajaxOptions, thrownError){  
                        alert(xhr.status);          
                        alert(thrownError);
                    } 
    
    
                });
    
                function parse(document){
                    $(document).find("Details").each(function(){
    
    
                        $("#leftnav").append(
    
    
                        '<li>' + '<a href="#">' + '<img src="images/album-xx.jpg" />' +
                            '<h3>' + $(this).find('Name').text() + '</h3>' +
                            '<p>' + $(this).find('Number').text() + '</p>' +
                            '</a>' + '</li>'
                    );
                    });
                }
            });
    

    Whats wrong?

    Thanks!

    解决方案

    Well, to trigger the automatic style on new elements, using .trigger("create") should do the job.

    see : Is it possible to create element on the fly with jQuery Mobile?

    or http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/pages/page-scripting.html

    EDIT: $('#leftnav').listview('refresh') is the thing your looking for rather than create.

    see: http://api.jquerymobile.com/listview/#method-refresh

    这篇关于JQuery 移动 ->.append() 删除 CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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