本文主要和大家分享js獲取短信驗證碼按鈕倒計時代碼,希望能幫助到大家。
(function(){ // 快速咨詢 $('#getCode').click(function() { var mobile = $('#mobile').val();//手機號碼的值 var _this = $(this); var mobileReg = /^1[3|4|5|7|8]\d{9}$/; //手機號正則 var phoneflag = mobileReg.test(mobile); if (!phoneflag) { alert('手機號碼格式不正確!'); } else { //User/getCode.html這個是后臺接口 $.post("/User/getCode.html", { mobile: mobile }, function(data) { _this.attr("disabled", "disabled"); _this.css({background:"#eee"});//設置不可點顏色 var val = parseInt(_this.val()); var time = 60; _this.val(time + " S"); time--; var timer = setInterval(function() { val = time + " S"; _this.val(val); if (time > 0) { time--; } else { //原始顏色 _this.val("獲取驗證碼").removeAttr("disabled").css({background:"#66CCFF"});; clearInterval(timer); } }, 1000); }); } }); })();
效果圖:
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com