JS實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)的注冊(cè)頁(yè)面
原型圖
需求:手機(jī)號(hào)驗(yàn)證
發(fā)送驗(yàn)證碼之后開(kāi)始60S倒計(jì)時(shí)
60s以后如果沒(méi)有填寫(xiě)驗(yàn)證碼,可重新發(fā)送
<!doctype html> <html> <head> <meta charset="utf-8"> <title>注冊(cè)</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no"> <meta name="renderer" content="webkit"> <meta http-equiv="Cache-Control" content="no-siteapp" /> <script src="http://code.jquery.com/jquery-latest.js";></script> </head> <body> <input type="text" id="phone" class="am-form-field my-radius" placeholder="請(qǐng)輸入手機(jī)號(hào)" style=""> <div style="height:2rem;"> <font id="errMsg1" color="red" style=""></font> </div> <div> <input id="rpcode" type="text" placeholder="請(qǐng)輸入驗(yàn)證碼"> <input id="getCode" type="button" value="獲取驗(yàn)證碼" onclick="sendMessages()"></input> <font id="errMsg2" color="red" style="display:none; position:absolution; top:2rem;"></font> </div> <p id="start"> <span>開(kāi)始</span> </p> <!-- 保存驗(yàn)證碼 --> <input type="text" id="code" hidden="true"> <script> var InterValObj; //timer變量,控制時(shí)間 var count = 60; //間隔函數(shù),1秒執(zhí)行 var curCount; //當(dāng)前剩余秒數(shù) var code = ""; //驗(yàn)證碼 var codeLength = 6; //驗(yàn)證碼長(zhǎng)度 function sendMessages() { curCount = count; var phone = $("#phone").val() if(validatePhone(phone)) { return; } if(phone != "") { //設(shè)置button效果,開(kāi)始計(jì)時(shí) $("#getCode").attr("disabled", "true"); $("#getCode").val("請(qǐng)?jiān)? + curCount + "秒內(nèi)輸入"); InterValObj = window.setInterval(SetRemainTimes, 1000); //啟動(dòng)計(jì)時(shí)器,1秒執(zhí)行一次 //向后臺(tái)發(fā)送處理數(shù)據(jù) $.ajax({ url: "getCode.action", dataType: "json", type: "get", data: "phone=" + phone, success: function(data) { //保存驗(yàn)證碼 $("#code").val(data); } }); } else { alert("手機(jī)號(hào)碼不能為空!?。。。?!"); } } //timer處理函數(shù) function SetRemainTimes() { if(curCount == 0) { window.clearInterval(InterValObj); //停止計(jì)時(shí)器 $("#getCode").removeAttr("disabled"); //啟用按鈕 $("#getCode").val("重新發(fā)送驗(yàn)證碼"); code = ""; //清除驗(yàn)證碼。如果不清除,過(guò)時(shí)間后,輸入收到的驗(yàn)證碼依然有效 } else { curCount--; $("#getCode").val("請(qǐng)?jiān)? + curCount + "秒內(nèi)輸入"); } } //開(kāi)始按鈕點(diǎn)擊事件 $("#start").click(function() { window.location.href = "regafter.html?phone=" + $("#phone").val(); }) //驗(yàn)證手機(jī)號(hào) function validatePhone(phone) { if(phone == '') { $("#errMsg1").html(" 請(qǐng)先填寫(xiě)手機(jī)號(hào)"); $("#errMsg1").show(); return true; } var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if(!myreg.test(phone)) { $("#errMsg1").html(" 請(qǐng)輸入有效的手機(jī)號(hào)"); $("#errMsg1").show(); return true; } return false; } //驗(yàn)證碼非空和錯(cuò)誤驗(yàn)證 function validateCode() { var phone = $("#phone").val(); var code = $("#code").val(); var rpcode = $("#rpcode").val(); if(validatePhone(phone)) { return true; } if(code == '') { $("#errMsg2").html(" 請(qǐng)先獲取驗(yàn)證碼"); $("#errMsg2").show(); return true; } if(rpcode == '' || code != rpcode) { $("#errMsg2").html(" 請(qǐng)正確輸入驗(yàn)證碼"); $("#errMsg2").show(); return true; } alert(code != rpcode); return false; } $("#phone").on("focus", function() { $("#errMsg1").hide(); }) $("#rpcode").on("focus", function() { $("#errMsg2").hide(); }) </script> </body> </html>
- 用javascript制作qq注冊(cè)動(dòng)態(tài)頁(yè)面
- jsp+dao+bean+servlet(MVC模式)實(shí)現(xiàn)簡(jiǎn)單用戶登錄和注冊(cè)頁(yè)面
- 使用JSP實(shí)現(xiàn)簡(jiǎn)單的用戶登錄注冊(cè)頁(yè)面示例代碼解析
- JS一個(gè)簡(jiǎn)單的注冊(cè)頁(yè)面實(shí)例
- JavaScript 完成注冊(cè)頁(yè)面表單校驗(yàn)的實(shí)例
- node.js實(shí)現(xiàn)登錄注冊(cè)頁(yè)面
- 原生js驗(yàn)證簡(jiǎn)潔注冊(cè)登錄頁(yè)面
- js正則表達(dá)式注冊(cè)頁(yè)面表單驗(yàn)證
- js當(dāng)前頁(yè)面登錄注冊(cè)框,固定div,底層陰影的實(shí)例代碼
- JS當(dāng)前頁(yè)面登錄注冊(cè)框,固定DIV,底層陰影的實(shí)例代碼
- javascript實(shí)現(xiàn)信息的顯示和隱藏如注冊(cè)頁(yè)面
- php用戶注冊(cè)頁(yè)面利用js進(jìn)行表單驗(yàn)證具體實(shí)例
- JS、CSS和HTML實(shí)現(xiàn)注冊(cè)頁(yè)面
相關(guān)文章
js網(wǎng)頁(yè)滾動(dòng)條滾動(dòng)事件實(shí)例分析
這篇文章主要介紹了js網(wǎng)頁(yè)滾動(dòng)條滾動(dòng)事件的用法,實(shí)例分析了javascript中window.onscroll監(jiān)控滾動(dòng)條滾動(dòng)事件的相關(guān)技巧,需要的朋友可以參考下2015-05-05(currentStyle)javascript為何有時(shí)用style得不到已設(shè)定的CSS的屬性
(currentStyle)javascript為何有時(shí)用style得不到已設(shè)定的CSS的屬性...2007-08-08javascript中巧用“閉包”實(shí)現(xiàn)程序的暫停執(zhí)行功能
javascript中巧用“閉包”實(shí)現(xiàn)程序的暫停執(zhí)行功能...2007-04-04JS中的public和private對(duì)象,即static修飾符
先看下面的例子,它將告訴我們?cè)贘S世界中也有C#里的public , private ,及static等2012-01-01JavaScript中的Array 對(duì)象(數(shù)組對(duì)象)
Array 對(duì)象用于在單個(gè)的變量中存儲(chǔ)多個(gè)值。2016-06-06TypeScript裝飾器之項(xiàng)目數(shù)據(jù)轉(zhuǎn)換詳解
這篇文章主要為大家詳細(xì)介紹了TypeScript項(xiàng)目中是如何進(jìn)行數(shù)據(jù)轉(zhuǎn)換的,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-10-10js實(shí)現(xiàn)帶三角符的手風(fēng)琴效果
本文主要介紹了js實(shí)現(xiàn)帶三角符手風(fēng)琴效果的實(shí)例。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-03-03一個(gè)兼容FF的智能超長(zhǎng)文章分頁(yè)JS
這篇文章主要介紹了一個(gè)兼容FF的智能超長(zhǎng)文章分頁(yè)JS的相關(guān)資料,需要的朋友可以參考下2007-07-07