1

每次,添加到进度条函数运行时,它都会使 cookie 的值加倍,每次 5 秒倒计时计时器结束时,它应该加 10。

任何人都可以帮助指出为什么它在添加后设置时会加倍 cookie 值。

<script>
    $(document).ready(function () {
        function startContdown() {
            var fiveSeconds = new Date().getTime() + 5000;
            $('#clock').countdown(fiveSeconds, { elapse: true })
                .on('update.countdown', function (event) {
                    if (event.elapsed) {
                        $('#clock').text("countdown ended");
                        addToProgressBar(Cookies.get("test"))
                        startContdown()
                    }
                    else {
                        var $this = $(this);
                        $this.html(event.strftime('Will refresh in <span>%S</span> seconds '))
                    }
                });
        }
        function addToProgressBar(val1) {
            cookieValue = Number(val1) + 10;
            Cookies.set("test", cookieValue);
            $('#progress1').animate({
                'width': (cookieValue)
            }, 100);

            $({ counter: 1 }).animate({ counter: cookieValue / 500 * 100 }, {
                duraton: 100,
                step: function () {
                    $('#progress1').text(Math.ceil(this.counter) + ' %');
                }
            })
        }
        Cookies.set("test", 0);
        startContdown()
    });
</script>
4

0 回答 0