Jquery插件實現(xiàn)點擊獲取驗證碼后60秒內(nèi)禁止重新獲取
通過jquery.cookie.js插件可以快速實現(xiàn)“點擊獲取驗證碼后60秒內(nèi)禁止重新獲取(防刷新)”的功能
效果圖:
先到官網(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(){
/*仿刷新:檢測是否存在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("獲取驗證碼").removeClass('disabled').removeAttr('disabled style');
}
}, 1000);
}
/*點擊改變按鈕狀態(tài),已經(jīng)簡略掉ajax發(fā)送短信驗證的代碼*/
$('#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("獲取驗證碼").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="請輸入手機號碼">
<input type="button" id="getting" value="獲取驗證碼">
</div>
</body>
</html>
以上就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
jQuery操作復(fù)選框(CheckBox)的取值賦值實現(xiàn)代碼
這篇文章主要介紹了jQuery操作復(fù)選框(CheckBox)的取值賦值實現(xiàn)代碼,需要的朋友可以參考下2017-01-01解決html-jquery/js引用外部圖片時遇到看不了或出現(xiàn)403的問題
下面小編就為大家?guī)硪黄鉀Qhtml-jquery/js引用外部圖片時遇到看不了或出現(xiàn)403的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09JQuery使用數(shù)組遍歷跳出each循環(huán)
這篇文章主要介紹了JQuery使用數(shù)組遍歷跳出each循環(huán),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09jquery實現(xiàn)點擊查看更多內(nèi)容控制段落文字展開折疊效果
這篇文章主要介紹了jquery實現(xiàn)點擊查看更多內(nèi)容控制段落文字展開折疊效果,涉及jquery中fadeIn與fadeOut實現(xiàn)折疊與展開頁面元素的功能,非常具有實用價值,需要的朋友可以參考下2015-08-08