首页 > 代码库 > asp 时间倒数后按钮可用

asp 时间倒数后按钮可用

  <asp:Button runat="server" ID="btn"  Text="免费获取验证码" onclick="btn_Click" />

js:

<script type="text/javascript">       var wait = 6;       function time() {           if (wait == 0) {               document.getElementById("btn").removeAttribute("disabled");               document.getElementById("btn").value = http://www.mamicode.com/"免费获取验证码";               wait = 6;           } else {               document.getElementById("btn").setAttribute("disabled", true);               document.getElementById("btn").value = http://www.mamicode.com/wait + "秒后可以重新发送";               wait--;               setTimeout(function () {                   time()               },            1000)           }       }     </script>    

后台页面加载时调用js

  protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {             ClientScript.RegisterStartupScript(GetType(), "js", "time()", true);        }    }

 

效果图:

asp 时间倒数后按钮可用