Jquery插件實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼后60秒內(nèi)禁止重新獲取
通過jquery.cookie.js插件可以快速實(shí)現(xiàn)“點(diǎn)擊獲取驗(yàn)證碼后60秒內(nèi)禁止重新獲?。ǚ浪⑿拢钡墓δ?/p>
效果圖:

先到官網(wǎng)(http://plugins.jquery.com/cookie/)下載cookie插件,放到相應(yīng)文件夾,代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script src=" <script src="jquery.cookie.js" ></script>
<style type="text/css">
* {margin: 0; padding: 0; font-family: "Microsoft Yahei";}
.captcha-box {width: 360px; height: 34px; margin: 30px; padding: 30px; border: #956E6F 1px dashed; border-radius: 5px; background-color: #FAF2F2;}
#mobile { float: left; width: 180px; height: 32px; border: #e5e5e5 1px solid; line-height: 32px; text-indent: 8px; outline: none;}
#getting {float: left; height: 34px; margin-left: -1px; padding: 0 18px; text-align: center; line-height: 34px; border: #e5e5e5 1px solid; background: linear-gradient(0deg, #f4f2f2 0%,#fbf9f9 100%); cursor: pointer; outline: none;}
</style>
<script>
$(function(){
/*仿刷新:檢測(cè)是否存在cookie*/
if($.cookie("captcha")){
var count = $.cookie("captcha");
var btn = $('#getting');
btn.val(count+'秒后可重新獲取').attr('disabled',true).css('cursor','not-allowed');
var resend = setInterval(function(){
count--;
if (count > 0){
btn.val(count+'秒后可重新獲取').attr('disabled',true).css('cursor','not-allowed');
$.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
}else {
clearInterval(resend);
btn.val("獲取驗(yàn)證碼").removeClass('disabled').removeAttr('disabled style');
}
}, 1000);
}
/*點(diǎn)擊改變按鈕狀態(tài),已經(jīng)簡(jiǎn)略掉ajax發(fā)送短信驗(yàn)證的代碼*/
$('#getting').click(function(){
var btn = $(this);
var count = 60;
var resend = setInterval(function(){
count--;
if (count > 0){
btn.val(count+"秒后可重新獲取");
$.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
}else {
clearInterval(resend);
btn.val("獲取驗(yàn)證碼").removeAttr('disabled style');
}
}, 1000);
btn.attr('disabled',true).css('cursor','not-allowed');
});
});
</script>
</head>
<body>
<div class="captcha-box">
<input type="text" id="mobile" maxlength="11" placeholder="請(qǐng)輸入手機(jī)號(hào)碼">
<input type="button" id="getting" value="獲取驗(yàn)證碼">
</div>
</body>
</html>
以上就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
- JQuery實(shí)現(xiàn)簡(jiǎn)單驗(yàn)證碼提示解決方案
- jquery實(shí)現(xiàn)手機(jī)發(fā)送驗(yàn)證碼的倒計(jì)時(shí)代碼
- jQuery實(shí)現(xiàn)發(fā)送驗(yàn)證碼并60秒倒計(jì)時(shí)功能
- jQuery插件實(shí)現(xiàn)靜態(tài)HTML驗(yàn)證碼校驗(yàn)
- jQuery 點(diǎn)擊獲取驗(yàn)證碼按鈕及倒計(jì)時(shí)功能
- jQuery實(shí)現(xiàn)驗(yàn)證碼功能
- jQuery實(shí)現(xiàn)一個(gè)簡(jiǎn)單的驗(yàn)證碼功能
- jquery實(shí)現(xiàn)表單獲取短信驗(yàn)證碼代碼
- jQuery實(shí)現(xiàn)的手機(jī)發(fā)送驗(yàn)證碼倒計(jì)時(shí)效果代碼分享
- js實(shí)現(xiàn)3D輪播圖效果
相關(guān)文章
jQuery時(shí)間戳和日期相互轉(zhuǎn)換操作示例
這篇文章主要介紹了jQuery時(shí)間戳和日期相互轉(zhuǎn)換操作,結(jié)合實(shí)例形式分析了jQuery針對(duì)日期與時(shí)間戳的轉(zhuǎn)換、運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
關(guān)于query Javascript CSS Selector engine
本篇文章,小編將為大家介紹,關(guān)于query Javascript CSS Selector engine,有需要的朋友可以參考一下2013-04-04
jQuery獲取某天的農(nóng)歷日期并判斷是否除夕或新年的方法
這篇文章主要介紹了jQuery獲取某天的農(nóng)歷日期并判斷是否除夕或新年的方法,涉及jQuery針對(duì)日期與時(shí)間的相關(guān)操作技巧,需要的朋友可以參考下2016-03-03
jQuery實(shí)現(xiàn)漂亮實(shí)用的商品圖片tips提示框效果(無圖片箭頭+陰影)
這篇文章主要介紹了jQuery實(shí)現(xiàn)漂亮實(shí)用的商品圖片tips提示框效果,具有鼠標(biāo)滑過顯示動(dòng)態(tài)提示框的效果,涉及針對(duì)鼠標(biāo)事件的響應(yīng)及頁(yè)面元素動(dòng)態(tài)操作技巧,需要的朋友可以參考下2016-04-04
使用jQuery UI庫(kù)開發(fā)Web界面的簡(jiǎn)單入門指引
這篇文章主要介紹了使用jQuery UI庫(kù)開發(fā)Web界面的簡(jiǎn)單入門指引,jQuery UI是一個(gè)基于jQuery的圖形組件庫(kù),需要的朋友可以參考下2016-04-04
jQuery中實(shí)現(xiàn)prop()函數(shù)控制多選框(全選,反選)
下面小編就為大家?guī)硪黄猨Query中實(shí)現(xiàn)prop()函數(shù)控制多選框(全選,反選)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
ASP.NET中AJAX 調(diào)用實(shí)例代碼
最近在ASP.NET中做了一個(gè)AJAX調(diào)用 : Client端先從ASP.NET Server后臺(tái)取到一個(gè)頁(yè)面模板,然后在頁(yè)面初始化時(shí)再?gòu)腟erver中取一些相關(guān)數(shù)據(jù)以實(shí)現(xiàn)頁(yè)面模板的動(dòng)態(tài)顯示2012-05-05

