js实现等待n秒后--按钮可用

时间:2021-11-04 12:27:44
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript">
        var count = 10;
       var tmrid= setInterval("setvalue()", 1000);
        event.cancelBubble=true
        function setvalue()
        {
            var btn = document.getElementById("btn");
            if (count > 0) {
                btn.value = "等待" + count + "秒";
                count--;
                btn.disabled = true;
            }
            else {
                btn.value = "同意"
                clearInterval("tmrid");
                btn.disabled = false;
            }
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="btn" type="button" value="同意" />
    </div>
    </form>
</body>
</html>