它遲到了很可能是我完全缺失和愚蠢的東西,但爲什麼它不更新單擊元素上的數據值和跨度內的計數的任何想法?jQuery點擊函數來獲取數據計數並應用於跨度計數
// simple like count function for demo
$('.action-like').on('click tap', function() {
var currentCount = $(this).data('like-count');
var newCount = currentCount + 1;
$(this).data('like-count', newCount);
$(this).find('.count').html(newCount);
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p><a href="#" class="btn btn--secondary action-like" data-like-count="1">Like</a> <span class="small"><span class="count">1</span> person likes this</span>
</p>
<p><a href="#" class="btn btn--primary action-like" data-like-count="5">Like</a> <span class="small">You and <span class="count">5</span> other people like this</span>
</p>
不要忘記標記答案及/給予好評,如果其中任何一個就足夠了。 –
我知道,我之前沒有讓我知道,因爲在我可以標記它之前必須有一定的/最少的分鐘數。 – James