<input id="sendEmail" type="button" name="sendEmail" onclick="show()" value="发送" style="cursor:pointer; width:218px;margin-left:3px;text-indent:0;text-align:center;margin-top:10px;"/>
function writeCookie(name, value, timeNum) {//把当前发送的时间写入cookie
var expire = "";
if (timeNum != null) {
expire = new Date((new Date()).getTime() + timeNum);//设置有效时间段(当前时间+设置的有效时间长度)
expire = "; expires=" + expire.toGMTString();//这里分号是为与前面的拼接需要"name=xxx;expires=yyy"
}
document.cookie = name + "=" + escape(value) + expire + ";path=/";
}
function readCookie(name) {//读取cookie中名称等于name的值
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = (document.cookie.substring(offset, end))
}
}
return cookieValue;
} var tipId;
function show() {
writeCookie("daTime", (new Date()).getTime(), 60000)
tipId = window.setInterval("start()", 1000);
}
$(function () {
var tt = parseInt(((new Date()).getTime() - readCookie("daTime")) / 1000);
if (tt < 60) {
tipId = window.setInterval("start()", 1000);
var vv = "(" + parseInt(60 - tt) + ")秒后重新发送";
$("#sendEmail").attr("disabled", "disabled");
$("#sendEmail").attr("value", vv);
}
})
function start() {
var tt = parseInt(((new Date()).getTime() - readCookie("daTime")) / 1000);
if (tt < 60) {
var vv = "(" + parseInt(60 - tt) + ")秒后重新发送";
$("#sendEmail").attr("disabled", "disabled");
$("#sendEmail").attr("value", vv); } else {
$("#sendEmail").removeAttr("disabled");
$("#sendEmail").attr("value", "发送");
window.clearInterval(tipId);
}
}

  

jQuery验证码发送时间秒递减(刷新存储cookie)的更多相关文章

  1. jQuery实现发送验证码30s倒计时,且刷新页面时有效

    在这里讲一讲这个案例的实现思路吧(个人见解)..核心思想:为防止页面刷新时倒计时失效的解决方案是:当每次刷新一次页面时都执行一个函数 即下面讲到的 setStyle() 函数.这个函数会根据当前的 c ...

  2. Jquery插件实现点击获取验证码后60秒内禁止重新获取

    通过jquery.cookie.js插件可以快速实现“点击获取验证码后60秒内禁止重新获取(防刷新)”的功能 先到官网(http://plugins.jquery.com/cookie/ )下载coo ...

  3. 基于JQuery+JSP的无数据库无刷新多人在线聊天室

    JQuery是一款非常强大的javascript插件,本文就针对Ajax前台和JSP后台来实现一个无刷新的多人在线聊天室,该实现的数据全部存储在服务端内存里,没有用到数据库,本文会提供所有源程序,需要 ...

  4. react项目中登陆注册验证码的倒计时,页面刷新不会重置

    目前很多的网站和app在做登陆注册时都会用到手机验证码,为了防止验证码轰炸,也就是随意的点击验证码,一般我们需要对获取验证码进行一些限制,最常用到的是在规定时间内不得重复发送. 实现倒计时很简单,可以 ...

  5. asp.net mvc 接入美圣短信 验证码发送

    第1步:登录美圣短信控制台 http://www.rcscloud.cn/hy/HY_ZH/login 账号:******* 密码:******* http://www.rcscloud.cn/com ...

  6. asp.net mvc 接入阿里大于 短信验证码发送

    项目前端页面实例 第1步:登录阿里大于控制台 https://www.alidayu.com/center/user/account?spm=0.0.0.0.P1K1jG 第2步:创建应用 第3步:配 ...

  7. jquery访问浏览器本地存储cookie,localStorage和sessionStorage

    前言:cookie,localStorage和sessionStorage都是浏览器本地存储数据的地方,其用法不尽相同:总结一下基本的用法. 一.cookie 定义: 存储在本地,容量最大4k,在同源 ...

  8. spring boot 学习(九)小工具篇:?秒防刷新

    注解 + 拦截器:?秒防刷新 小工具篇:工具许多都是我以前在 github 之类开源平台找到的小工具类,作者的信息什么的许多都忘了.先说声不好意思了.若有相关信息,麻烦提醒一下~ 解释 所谓的?秒防刷 ...

  9. Spring Security构建Rest服务-0801-短信验证码发送

    实现短信验证码登录 开发短信验证码接口 校验短信验证码并登录 短信验证码和图片验证码开发思路类似: 1,我们访问一个controller 2,在controller里调用短信验证码生成接口生成验证码 ...

随机推荐

  1. SpringBoot Cloud eureka 注册中心

    SpringBoot Cloud是什么 Spring Cloud是一个分布式的整体解决方案. Spring Cloud 为开发者提供了在分布式系统(配置管理,服务发现,熔断,路由,微代理,控制总线,一 ...

  2. idea 项目热部署设置

    1.引入pom.xml() <!-- 热部署(必须) --> <dependency> <groupId>org.springframework.boot</ ...

  3. python 子类继承父类属性及实例化方法

  4. pl/sql基础知识—过程快速入门

    n  过程 过程用于执行特定的操作,当建立过程时,既可以指定输入参数(in),也可以指定输出参数(out),通过在过程中使用输入参数,可以将数据传递到执行部分:通过使用输出参数可以将执行部分的数据传递 ...

  5. Linux下配置 Keepalived(心跳检测部署)

    首先呢,我想先给大家简单介绍一下什么是keepalived: Keepalived的作用是检测服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的服务器 ...

  6. HTML5入门指南

    1.HTML5到底是什么? HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定.目标是取代1999年所制定的HTML 4.01和XHTML 1.0标准,以期能在互联 ...

  7. LeetcCode102 Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  8. JS 的私有成员为什么钦定了 #?

    翻译自 tc39/proposal-class-fields 译者按:社区一直以来有一个声音,就是反对使用 # 声明私有成员.但是很多质疑的声音过于浅薄.人云亦云.其实 TC39 早就对此类呼声做过回 ...

  9. OpenStack组件系列☞horizon搭建

    第一步:部署horizon环境: 安装部署memcache 安装软件包 yum install memcached python-memcached 启动memcache并且设置开机自启动 syste ...

  10. @loj - 2483@「CEOI2017」Building Bridges

    目录 @desription@ @solution@ @accepted code@ @details@ @another solution@ @another code@ @desription@ ...