用于一些注冊類的場景,點擊發送驗證碼,xx秒后重新發送。
利用 setTimeout 方法,xx秒后執行指定的方法,修改button的屬性值,disabled為true時為灰色,不可點擊。
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><!--<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>--><script type="text/javascript"> var countdown=60; function settime(obj) { if (countdown == 0) { obj.removeAttribute("disabled"); obj.value="獲取驗證碼"; countdown = 60; return; } else { obj.setAttribute("disabled", true); obj.value="重新發送(" + countdown + ")"; countdown--; } setTimeout(function() { settime(obj); } ,1000);} </script><body><label> <input type="text" name="textfield"></label><input type="button" id="btn" value="獲取驗證碼" onclick="settime(this)" /> </body></html>
總結
以上所述是小編給大家介紹的JS實現點擊發送驗證碼 xx秒后重新發送功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
新聞熱點
疑難解答