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 = "免费获取验证码";
               wait = 6;
           } else {
               document.getElementById("btn").setAttribute("disabled", true);
               document.getElementById("btn").value = wait + "秒后可以重新发送";
               wait--;
               setTimeout(function () {
                   time()
               },
            1000)
           }
       }
     
</script>    

后台页面加载时调用js

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

 

效果图:

posted on 2014-11-25 11:16  小东北  阅读(563)  评论(0编辑  收藏  举报