[英]not working jquery in a ajax loaded part
我用Ajaxtabs加載了一些頁面ajax,我在頁面jquery和owl carousel中使用但是在加載部件之后,jquery不起作用並且給了div的owl類和樣式。
我的主頁:
<div class="tabsbar">
<ul id="countrytabs" class="tabsheader container">
<li><a href="#" rel="#default" class="selected">first tab no ajax</a></li>
<li><a href="one.php" rel="countrycontainer">test tab ajax</a></li>
<li><a href="two.php" rel="countrycontainer">test tab ajax</a></li>
<li><a href="three.php" rel="countrycontainer">test tab ajax</a></li>
</ul>
</div>
<div id="countrydivcontainer" class="tabsbody">
<p>first tab content that no ajax</p>
</div>
one.php&two.php&three.php是我的wordpress自定義頁面鏈接
在one.php中:
<?php /* Template Name: CustomPage1 */ ?>
<div class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'print', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<div class="product item">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="287px" height="227px" />'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<script type='text/javascript'>
$(document).ready(function(){
$('.products').owlCarousel({
loop:true,
responsiveClass:true,
responsive:{
0:{
items:2,
},
768:{
items:4,
},
992:{
items:6,
}
}
});
});
</script>
如你所見,我在一個頁面中保存了10個woocommerce帖子,我想加載它作為ajax,html代碼加載好,但jquery不適用於這個ajax加載的部分。
另一個奇怪的問題當我將輪播放在#countrydivcontainer中的第一個標簽中時,瀏覽器中的第一個視圖不是ajax正常工作但是當我在標簽之間切換並加載其他部件並返回第一個標簽時,這也無效。
檢查你是否正在調用最新的jQuery
check also that you have added wp_head(); in header.php and wp_fooer(); in footer.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.