js實現驗證碼倒計時效果

來源:互聯網
上載者:User

標籤:計時   function   input   .post   attr   settime   this   timeout   countdown   

<input type="button" id="btn" value="擷取驗證碼" onclick="getrand(this);"/> 

一、已上是點擊擷取驗證碼的點擊區。

二、以下是js代碼

var countdown = 60;

function getrand(obj) {

if(countdown == 60){

$.post("/Home/Index/randNum",

function (data) {

document.getElementById(‘sjs‘).value = data;

} )

}

//以上$.post是為了從後台得到一個隨機數進行驗證,可以忽略,不影響倒計時60s效果,而且還完美的只從後台產生了一個隨機數。

if (countdown == 0) {

obj.removeAttribute("disabled");

obj.value = "擷取驗證碼";

countdown = 60;

return;

} else

{ obj.setAttribute("disabled", true);

obj.value = "重新發送(" + countdown + ")";

countdown--;

}

setTimeout(

function() { getrand(obj); },

1000)

}

js實現驗證碼倒計時效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.