Increment a number by clicking onto a button

前端 未结 2 1714
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 01:04

I have the number $likes_number in a div block on my page. I would like to know how to increment it dynamically by clicking on a button?

My code

2条回答
  •  误落风尘
    2021-01-01 01:27

    $('#like').click(function() {
        $('#likes span').text( parseInt($('#likes span').text()) + 1 );
    });
    

    You can see an example here: http://jsfiddle.net/nayish/GCvnH/

提交回复
热议问题