简体   繁体   English

当模板在jQuery Mobile中用Ajax加载时,touchcarousel不起作用

[英]touchcarousel not working when template loaded with ajax in jquery mobile

index.php index.php

<div id="carousel-image-and-text" class="touchcarousel grey-blue sbSlider">       
      <ul class="touchcarousel-container  item-list"  <?php echo "id='".$catId."'"; ?> > 
      </ul> 
</div>

js: js:

 $(document).live( "pagebeforecreate", function( e, data ) { 
                    $( ".item-list" ).each(function( index ) { 
                        var id = $(this).attr("id");  
                       $.ajax({ 
                            url: "/test.html",
                            context: document.body
                             }).done(function(html) {  
                               // $("#"+id).append(html); 
                              $("#"+id).replaceWith(html);
                        });  
                       // alert(id); 
                     }); 

      });

test.html test.html

 <li class="touchcarousel-item"><a href="gift-page.html"><span><img src="/images/spacer.gif" style="background:url(https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/p128x128/851586_168401033316275_1834897920_n.png) no-repeat center center; background-size:auto 50px"/></span><strong>Napoli</strong><font>Food and Drinks</font><label><i></i>15</label></a></li>
   <li class="touchcarousel-item"><a href="gift-page.html"><span><img src="/images/spacer.gif" style="background:url(https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/p128x128/851586_641022952579983_1053547819_n.png) no-repeat center center; background-size:auto 50px"/></span><strong>Pusheen</strong><font>Food and Drinks</font><label>FREE</label></a></li>

Correct me if i am wrong, but it seems like you are replacing your <UL> with and <LI> . 如果我错了,请纠正我,但似乎您正在用和<LI>代替<UL> <LI> So this means you will only have <LI> with out an <UL> . 因此,这意味着您只有<LI>而没有<UL> In this case i think you should use .append instead of .replaceWith 在这种情况下,我认为您应该使用.append而不是.replaceWith

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM