2017-08-16 23 views
0

我希望使這行$(".load-more").text("No more.");文字只能加載更多的不可點擊的鏈接。如何使ajax div只是文本?

如果有人可以幫忙,我該如何做到這一點?

<script type="text/javascript"> 
$(document).ready(function(){ 
    // Load more data 
    $('.load-more').click(function(){ 
     var row = Number($('#row').val()); 
     var catid = Number($('#catid').val()); 
     var allcount = Number($('#all').val()); 
     row = row + <?php echo $records_per_page; ?>; 
     if(row <= allcount){ 
      $("#row").val(row); 
      $.ajax({ 
       url: '<?php echo DIR; ?>getCat.php', 
       type: 'post', 
       data: {row:row,catid:catid}, 
       beforeSend:function(){ 
        $(".load-more").text("Loading..."); 
       }, 
       success: function(response){ 
        // Setting little delay while displaying new content 
        setTimeout(function() { 
         // appending posts after last post with class="post" 
         $(".post:last").after(response).show().fadeIn("slow"); 
         var rowno = row + <?php echo $records_per_page; ?>; 
         // checking row value is greater than allcount or not 
         if(rowno > allcount){ 

          // Change the text and background 
          $(".load-more").text("No more."); 
          $('.load-more').css("background","#FB0925"); 
         }else{ 
          $(".load-more").text("Load more."); 
         } 
        }, 2000); 
       } 
      }); 
     }else{ 
      $('.load-more').text("Loading..."); 
      // Setting little delay while removing contents 
      setTimeout(function() { 
       // When row is greater than allcount then remove all class='post' element after 3 element 
       $('.post:nth-child(3)').nextAll('.post').remove().fadeIn("slow"); 
       // Reset the value of row 
       $("#row").val(0); 
       // Change the text and background 
       $('.load-more').text("Load more"); 
       $('.load-more').css("background","#333333"); 
      }, 2000); 
     } 
    }); 
}); 
</script> 

我不太熟悉ajax,所以希望你們不要介意幫助。

感謝

+1

請包括相關的HTML與此去,所以我們可以更好地回答這個問題。也就是說,假設你的加載更多按鈕被包裝在一個鏈接中,可能會對jQuery的['.unwrap()'](https://api.jquery.com/unwrap/)感興趣。所以你的代碼只是'$('。load-more')。unwrap()。text('No more。');'。 – cjl750

回答

0

$(".load-more").text("No more."); 

把這個:

$('.load-more').css('pointer-events', 'none'); 
$('.load-more').click(function(){return false;}); 
+0

感謝作品像一個魅力:) –