Copyright 2013-2014 All Rights Reserved Theme by www.warewashingadvisors.com 版權(quán)所有
AB模板網(wǎng)(www.warewashingadvisors.com)專注企業(yè)網(wǎng)站模板制作,包括企業(yè)pbootcms網(wǎng)站模板,靜態(tài)網(wǎng)頁模板,網(wǎng)站源碼下載,HTML網(wǎng)站模板等等。XML地圖 網(wǎng)站地圖 今日更新
免責聲明:本站所有資源(模板、圖片)搜集整理于互聯(lián)網(wǎng)或者網(wǎng)友提供,僅供學習與交流使用,如果不小心侵犯到你的權(quán)益,請及時聯(lián)系我們刪除該資源。
當今的網(wǎng)站設(shè)計越來越注重用戶體驗,無刷新點贊就是其中之一。本文將介紹如何使用 Pbootcms 實現(xiàn)無刷新點贊功能。
首先,我們需要在頁面中引入 jQuery 文件,可以通過以下代碼實現(xiàn):
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> |
<button class="support">點贊</button> <!--按鈕---> <div id="support_number">{content:likes}</div> <!--贊數(shù)量--> <p class="supported"></p> <!--已贊提示--> <!--ajax--> <script> $('.support').on('click', //綁定事件 function() { $.ajax({ url: '{content:likeslink}', //點贊鏈接 data: { 'likes': 'likes' }, success: function(data) { $('#support_number').load(location.href + " #support_number"); //點贊后刷新#support_number if (data.state) {} else { $(".supported").html("已點贊!") //已贊提示 }}, error: function(xhr, status, error) { console.log(error) } }); }) </script> |
以上代碼中,class=”support” 表示點贊按鈕的類名,通過 jQuery 的 on() 方法綁定事件,點擊時觸發(fā)發(fā)送 AJAX 請求的操作。
在 AJAX 請求中,url 參數(shù)為點贊鏈接,data 參數(shù)傳遞點贊的數(shù)量。成功獲取返回值后,利用 load() 方法刷新顯示點贊數(shù)量的 DOM 元素 #support_number,同時判斷返回值狀態(tài)并根據(jù)需要顯示已點贊提示。
以上代碼即可實現(xiàn) Pbootcms 的無刷新點贊功能。不過在實際應(yīng)用中,還需要根據(jù)具體情況對代碼進行適當?shù)男薷暮驼{(diào)整。