Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery Mobile:当在多个页面中调用javascript函数时,滚动停止工作_Javascript_Jquery_Html_Jquery Mobile_Cordova - Fatal编程技术网

jQuery Mobile:当在多个页面中调用javascript函数时,滚动停止工作

jQuery Mobile:当在多个页面中调用javascript函数时,滚动停止工作,javascript,jquery,html,jquery-mobile,cordova,Javascript,Jquery,Html,Jquery Mobile,Cordova,我有一个函数,用于从JSON文件中获取信息并动态显示。我根据数组中元素的数量动态创建多个页面。当我将它应用于一个页面时,它可以完美地工作,但当我将它应用于多个页面(我需要)时,滚动功能停止工作,没有明显的原因。我把第二页改回原来的状态,第一页又开始工作了。这是我的JS函数,如果你能告诉我发生了什么,我将不胜感激 <script type="text/javascript"> $(document).on("pageinit", "#Page1", function(){

我有一个函数,用于从JSON文件中获取信息并动态显示。我根据数组中元素的数量动态创建多个页面。当我将它应用于一个页面时,它可以完美地工作,但当我将它应用于多个页面(我需要)时,滚动功能停止工作,没有明显的原因。我把第二页改回原来的状态,第一页又开始工作了。这是我的JS函数,如果你能告诉我发生了什么,我将不胜感激

    <script type="text/javascript">
$(document).on("pageinit", "#Page1", function(){ 
  var info="";
  var dpages="";
  var pageno=1;  
  var imp= "Json/empirical.json";
  $.getJSON(imp, function(data) {
     $.each(data.tcontent, function(i, item) {
        if(item.Name=='Skin and Soft Tissue Infections'){
           var search=item.Variations;
           $.each(search, function(j, subitem) {

            info += '<a href="#Paged'+ pageno + ' " data-role="button" data-mini="true">'+ subitem.condition +'</a><br>';

            dpages += '<div data-role="page"  data-theme="a" id="Paged' + pageno + '"> <div data-role="header" data-theme="c"><a data-rel="back" data-role="button" class="ui-btn-left" data-transition="flip" data-icon="back"> Back</a> <h2>'+ subitem.condition +'</h2> </div> <div data-role="content" data-theme="c" id="Paged '+ pageno +'_Content">  <p class="infotexttitle">Likely Organisms: </p> ' + subitem.organisms + ' <p class="infotexttitle"> Antimicrobial & Dosage </p> ' + subitem.antimicrobial + '  <p class="infotexttitle"> Alternative Antimicrobial: </p> ' + subitem.alternative + ' <div data-role="collapsible" data-mini="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" data-iconpos="right" data-theme="d" data-content-theme="d"> <h3> Comments: </h3> <p class="guidelinetext"> ' + subitem.comments + ' </p></div> </div> <div data-role="footer" data-theme="c"> <h2>(c) Darragh O Connor </h2></div> </div></div>';



            pageno++;                        
        });
    }
  $("#texts").empty().append(info).collapsibleset().trigger('create');
  $.mobile.pageContainer.append(dpages);
  }); }); });

$(document).on(“pageinit”,“#Page1”,function(){
var info=“”;
var dpages=“”;
var pageno=1;
var imp=“Json/emerical.Json”;
$.getJSON(imp,函数(数据){
$.each(data.t内容、功能(i、项){
如果(item.Name==‘皮肤和软组织感染’){
var搜索=item.Variations;
$.each(搜索,函数(j,子项){
信息+='
'; dpages+='Back'+subitem.condition+'

可能的生物体:

'+subitem.organics+'

抗菌剂和剂量

'+subitem.Antimicrobial+'

替代抗菌剂:

'+subitem.Alternative+'注释:

“+subitem.comments+”

(c)Darragh O Connor'; pageno++; }); } $(“#text”).empty().append(info).collapsableset().trigger('create'); $.mobile.pageContainer.append(dpages); }); }); });

您能否详细说明一下“当我将其应用于一个页面时,它可以完美地工作,但当我将其应用于多个页面时(我需要),滚动功能会停止工作,而没有明显的原因”?在其他页面上调用相同的函数?@Omar基本上该函数适应性很强。在if循环中,如果我更改item.Name,那么它将从同一个JSON文件生成全新的内容。所以我有大量的信息,我使用相同的函数访问不同的信息,这取决于我想要显示的内容。如果我只在一个页面上调用该函数,那么它工作得非常好。但是,当我在多个页面中使用同一个函数时,该函数调用的所有页面上的滚动都会停止工作。你明白吗?所以,每次调用该函数时,你都会创建更多的页面。确保所有标记都正确关闭,在一个小json数组上测试函数,直到发现问题为止。