倒计时

来源:互联网 发布:国际期货软件下载 编辑:程序博客网 时间:2024/06/05 15:59
<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8">
    <title>60s倒计时</title>
</head>


<body>
    <img src="">
    <a id="ii" href="javascript:">dianjihhh</a>
    <script type="text/javascript">


    function countdown(objId, _time) {
        document.addEventListener("DOMContentLoaded", function() {
            var obj = document.getElementById(objId),
                time = _time,
                content = obj.innerText;
            obj.onclick = function() {
                var _flag = this.getAttribute("data-flag");
                if (_flag == "doing") return;
                var cd = setInterval(function() {
                    obj.setAttribute("data-flag", "doing");
                    obj.onmouseover = function () {
                        this.style.cursor = "not-allowed";
                    }
                    obj.onmouseout = function () {
                        this.style.cursor = "pointer";
                    }
                    obj.onmouseover
                    obj.innerText = time + "S";
                    if (time === 0) {
                        obj.removeAttribute("data-flag");
                        clearInterval(cd);
                        obj.innerText = content;
                        time = _time;
                    } else {
                        time--;
                    }
                }, 1000);
            };
        });
    }


    countdown("ii", 5);
    </script>
</body>


</html>
0 0
原创粉丝点击