asp 時間倒數後按鈕可用

  <asp:Button runat="server" ID="btn"  Text="免費獲取驗證碼" onclick="btn_Click" />

js:javascript

<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>    

後臺頁面加載時調用jsjava

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

 

效果圖:spa

相關文章
相關標籤/搜索