【问题标题】:Ajax call for jquery mobile pages works but when refreshing loses css and js functionality用于 jquery 移动页面的 Ajax 调用有效,但刷新时会丢失 css 和 js 功能
【发布时间】:2011-09-06 20:51:03
【问题描述】:

我将下面的代码加载到一个 jquery 移动页面数据角色中。我注意到的两件奇怪的事情是,如果我尝试仅在其中加载一个页面,则不会仅为从脚本加载的项目加载 css 或 jquery 移动功能。另一件事是在页面刷新时它也会丢失它。数据仍然显示为纯文本。有没有其他人经历过这个?我也尝试了 pagecreate 功能而不是准备好文档,但它根本不起作用。谁能看到它为什么会在移动设备上这样做或提出一些建议?

提前致谢!

<script>
   $(document).ready(function(){

                      $.ajax({
                             type: "GET",
                             url: "oncology_testlist.xml",
                             dataType: "xml",
                             success: function(xml) {
                             var $ul = $("#testList");
                             var categories = new Object();
                             var category;
                             $(xml).find('test').each(function(){
                                                      category = $('category', this).text();
                                                      cat_nospaces = category.replace(/ /g,'');
                                                      if (!$('#cat_'+cat_nospaces).length) {
                                                      $ul.append('<div data-role="header" data-theme="a" id="cat_'+cat_nospaces+'"><h1>' + category + '</h1></div>');
                                                      }
                                                      $ul.append('<li><div data-role="collapsible" data-collapsed="true" data-theme="b">'
                                                                                     + '<h3>' + $('test_code', this).text() + " - " + $('name', this).text() + '</h3>'
                                                                                     + (!$.trim($('cpt_code', this).text())?'':'<p>' + "CPT Code(s): " + $('cpt_code', this).text() + '</p>')
                                                                                     + (!$.trim($('method', this).text())?'':'<p>' + "Method: " + $('method', this).text() + '</p>')
                                                                                     + (!$.trim($('clinical_utility', this).text())?'':'<p>' + "Clinical Utility: " + $('clinical_utility', this).text() + '</p>')
                                                                                     + '</div></li>');

                                                      });
                             }
                             }); 
                      });
    </script>    

【问题讨论】:

    标签: jquery-mobile


    【解决方案1】:

    搜索后修复...

    添加了 $('#testcatalog').trigger('create');在代码末尾。

    【讨论】:

      【解决方案2】:

      我用另一个解决方案解决了类似的问题:

      complete: function(){
                                $("#testcatalog").listview();
                                $("#testcatalog").listview('refresh'); 
                               },
      

      【讨论】:

        猜你喜欢
        • 2013-11-07
        • 1970-01-01
        • 1970-01-01
        • 2012-08-10
        • 2020-08-28
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 2014-12-31
        相关资源
        最近更新 更多