2016-12-25 16 views
0

我想在點擊頁碼時添加活動類,但是類在Ajax調用加載頁面時消失。在AJAX分頁問題中添加類「活動」

我嘗試過很多辦法來解決這個問題,但我不能,因爲

我怎樣才能解決這個問題?

function loadData(page) 
     { 
      $('.loading-info').show(); 
      if (typeof page === 'undefined') { 
       page = '' 
      } else{ 
       page = '&page='+page 
      } 
      $.ajax 
      ({ 
       type: "POST", 
       url: "../inc/ajax/ajax_view/user_assgined_view_hi.php", 
       data: "page="+page, 
       success: function(msg) 
       { 
        $("#results").html(msg); 
        $('.loading-info').hide(); 

       } 
      }); 
     } 


      $(document).on('click','.paging',function(e){ 
      var page = ($(this).attr("id")); 
      loadData(page); 
       if ($(this).hasClass('active')) { 
        $(this).removeClass('active'); 
       } else { 
        $(this).addClass('active'); 
       } 
     }); 
+0

你應該顯示你的html以及 – Bharat

回答

0

試試這個吧!

$(".paging").on("click", function(){ 
    var page = $(this).attr("id"); 
    $('.loading-info').show(); 

    if (typeof page === 'undefined') { 
     page = ''; 
    } else { 
     page = '&page=' + page 
    } 

    $.ajax({ 
     type: "POST", 
     url: "../inc/ajax/ajax_view/user_assgined_view_hi.php", 
     data: "page=" + page, 
     success: function(msg){ 
      $("#results").html(msg); 
      $('.loading-info').hide(); 
     } 
    }); 

    $(this).toggleClass("active"); 
}); 
+0

也不管用,調用loadData(page)後主動消失; – user3763103

+0

@ user3763103給我一個時刻 –

+0

@ user3763103立即嘗試:-) –