首页 > 技术文章 > JS倒计时执行操作

wangdahai 2016-11-25 17:26 原文

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    //换成你的jquery库
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        var setTime;
        $(document).ready(function(){
            var time=parseInt($("#time").text());
            setTime=setInterval(function(){
                if(time<=0){
                    clearInterval(setTime);
                    return;
                }
                time--;
                $("#time").text(time);
            },1000);
        });
    </script>
</head>
<body>
    <span id="time">60</span>
</body>
</html>

 

推荐阅读