javascript發(fā)送驗(yàn)證碼
一個(gè)發(fā)送驗(yàn)證碼的javascript代碼
var T = 0; var handle = null; var event = null; $(function(){ $('#sendCode').click(function(e){ if(T == 0) { var mobile = $('#name').val(); if (!/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(mobile)) { alert('請(qǐng)先填寫正確的手機(jī)號(hào)碼'); return false; } $.post('/auth/sendcode', {mobile: mobile, _token: 'HyOSLkoOpvawVZZi6LUYfNIryJZvc2mXnOJYrrDJ'}, function (res) { if (res.state == 'success') { T = 59; countDown(); } else { alert(res.message); } }, 'json'); } else { e.stopPropagation(); } }); }); function countDown() { $('#sendCode').text(T+'秒后可重新獲取').css({'background-color':'#f8f8f8', 'color' : '#cccccc'}); T = T - 1; handle = setTimeout('countDown()', 1000); if (T < 0) { clearTimeout(handle); $('#sendCode').text('重新獲取').css({'background-color':'#eeeeee', 'color' : '#555555'}); T = 0; } }
作者:Tyler Ning
出處:http://www.rzrgm.cn/tylerdonet/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,如有問題,請(qǐng)微信聯(lián)系冬天里的一把火
浙公網(wǎng)安備 33010602011771號(hào)