js倒计时 重发 效果

<script type="text/javascript">
            window.onload = function() {
                var wait = 60;

                function time(o) {
                    if (wait == 0) {
                        o.removeAttribute("disabled");
                        o.value = "重新获取验邮件";
                        wait = 60;
                    } else {
                        o.setAttribute("disabled", true);
                        o.value = "重新发送(" + wait + ")";
                        wait--;
                        setTimeout(function() {
                                time(o)
                            },
                            1000)
                    }
                }
                document.getElementById("btn").onclick = function() {
                        time(this);
                    }
                    // 0.5秒后模拟点击
                setTimeout(function() {
                    // IE
                    if (document.all) {
                        document.getElementById("btn").click();
                    }
                    // 其它浏览器
                    else {
                        var e = document.createEvent("MouseEvents");
                        e.initEvent("click", true, true);
                        document.getElementById("btn").dispatchEvent(e);
                    }
                }, 500);
            }
        </script>
<input type="button" id="btn" value="重新获取验邮件" class="button" />

 

posted @ 2015-11-10 13:18  webfby  阅读(301)  评论(0编辑  收藏  举报