在WordPress站点的while循环内的jQuery问题

时间:2019-04-27 07:40:00

标签: php jquery wordpress

jQuery在第二个网格后无法使用

   <div class="carousel slide carousel1" id="myCarousel1">
      <div class="carousel-inner"><?php 
       $args = array('post_type'=>'post','post_status'=>'publish','orderby'=>'menu_order','order'=>'ASC','posts_per_page'=>'2',
           'tax_query' => array(array('taxonomy' =>'category','field'=>'slug','terms'=>'videos')));
       $team = new WP_Query($args);
       if($team->have_posts()){
           while ( $team->have_posts() ) : $team->the_post();?>
              <div class="item">
                 <div class="panel col-md-4 col-xs-12">                        
                    <div class="panel-header">
                        <h4><?php the_title();?></h4>                                                      
                    </div>  

                 </div>
              </div><?php 
              endwhile;
           }?>                 
       </div>

    </div>

JS

 $(document).ready(function() {

      $( ".panel-header h4" ).click(function() {
            alert('sdfds');
        });
});

1 个答案:

答案 0 :(得分:1)

尝试一下:

jQuery(document).ready(function($) {
  $( ".panel-header h4" ).each(function() {
      $(this).click(function(){
         alert('sdfds');
      });

    });
});