第一步,给你要点赞的a标签或者button按钮添加 id="dianzan" 属性

第二步,给你需要显示点赞数的标签加上 class="likes-count" 属性

第三步,将下面的js代码放到你网站内容页


<script>
function makeRequest(url, callback, method) {
  var xhr = new XMLHttpRequest();
  xhr.open(method, url);
  xhr.onreadystatechange = function() {
  if (xhr.readyState === 4 && xhr.status === 200) {
    callback(xhr.responseText);
  }
  };
  xhr.send();
}

function updateLikes(event) {
  event.preventDefault(); // 阻止默认链接行为

  var likesCountElement = document.querySelector('.likes-count');
  var likeButton = document.getElementById('dianzan');
  var url = "/e/public/digg/?classid=[!--classid--]&id=[!--id--]&dotop=1&doajax=1&ajaxarea=diggnum";

  makeRequest(url, function(responseText) {
  var responseArray = responseText.split("|");
  var likes = responseArray[0];
  likesCountElement.textContent = likes;

  alert(responseArray[2]);
  }, "GET");
}

var likeButton = document.getElementById('dianzan');
likeButton.addEventListener('click', updateLikes);
</script>

 完成!