Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using the code below to get the value(number) inside a div and plus one but if the value is 1 and I am pressing my button it gives me 01 and I want to plus one and if it is 2 and press my button again it gives me 22.

My code is:

<div class="mybtn">0</div>

<script>

$(function() {

$(".buttonDown").click(function() 
{
var checkDown = $('.buttonDown').text();
$('.mybtn').hide("fast");
$('.mybtn').text(checkDown+1);
$('.mybtn').fadeIn("slow");
});

});
</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

$(function () {
    $(".mybtn").click(function () {
        var $this = $(this).stop(true, true).hide("fast");
        var checkDown = parseInt($.trim($(this).text()), 10);
        $this.text(checkDown + 1).fadeIn("slow");
    });
});

Demo: Fiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...