1. 程式人生 > >js實現頁面的秒數倒計時

js實現頁面的秒數倒計時

ble 頁面 dex out data sync 重新獲取驗證碼 cli cti

<button name="vcode_mail" class="btn btn-default" type="button" id="vcode_mail-btn" onclick="vcode_mail_post(this)">免費獲取驗證碼</button>

js

    //發送驗證碼
    function vcode_mail_post(obj){
        var seconds =121;

        //獲取郵箱
        var email = $("input[name=‘email‘]").val();
        //異步變同步
/*$.ajaxSettings.async = false;*/ //發送請求 $.post("{:url(‘index/user/vcode_mail_post‘)}",{email:email,type:1},function(data){ var message = data.message; if(data.ok == 1){ alert(message); //倒計時 daojishi(seconds,obj); }
else{ alert(message); } },json); /*$.ajaxSettings.async = true;*/ } //倒計時 function daojishi(seconds,obj){ if (seconds > 1){ seconds--; $(obj).text(seconds+"秒後可重新獲取 ").attr("disabled", true);//禁用按鈕
// 定時1秒調用一次 setTimeout(function(){ daojishi(seconds,obj); },1000); }else{ $(obj).text("重新獲取驗證碼").attr("disabled", false);//啟用按鈕 } }

技術分享圖片

js實現頁面的秒數倒計時