亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js代碼實(shí)現(xiàn)點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)

 更新時(shí)間:2021年01月28日 11:11:29   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了js代碼實(shí)現(xiàn)點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

比如,一些網(wǎng)站上的手機(jī)短信認(rèn)證的功能,有類似實(shí)現(xiàn)點(diǎn)擊按鈕后,倒計(jì)時(shí)60秒才能再次點(diǎn)擊發(fā)送的效果。

此例子用Javascript實(shí)現(xiàn)點(diǎn)擊按鈕后,倒計(jì)時(shí)60秒才能再次點(diǎn)擊發(fā)送驗(yàn)證碼的功能。

例子1:Javascript 實(shí)現(xiàn) 點(diǎn)擊按鈕 倒計(jì)時(shí)60秒方可再次點(diǎn)擊發(fā)送的效果

<input type="button" id="btn" value="免費(fèi)獲取驗(yàn)證碼" />
<script type="text/javascript">
var wait=60;
function time(o) {
 if (wait == 0) {
 o.removeAttribute("disabled"); 
 o.value="免費(fèi)獲取驗(yàn)證碼";
 wait = 60;
 } else { 

 o.setAttribute("disabled", true);
 o.value="重新發(fā)送(" + wait + ")";
 wait--;
 setTimeout(function() {
 time(o)
 },
 1000)
 }
 }
document.getElementById("btn").onclick=function(){time(this);}
</script>

例子2:點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)js代碼

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>無標(biāo)題文檔</title> 
<script type="text/javascript" src="js/jquery.js"></script> 
</head> 

<body> 
<input type="button" id="btn" value="免費(fèi)獲取驗(yàn)證碼" onclick="settime(this)" /> 
<script type="text/javascript"> 
var countdown=60; 
function settime(val) { 
if (countdown == 0) { 
val.removeAttribute("disabled"); 
val.value="免費(fèi)獲取驗(yàn)證碼"; 
countdown = 60; 
} else { 
val.setAttribute("disabled", true); 
val.value="重新發(fā)送(" + countdown + ")"; 
countdown--; 
} 
setTimeout(function() { 
settime(val) 
},1000) 
} 
</script> 
</body> 
</html>

例子3:點(diǎn)擊按鈕后,60秒倒計(jì)時(shí)后才能繼續(xù)可以點(diǎn)擊,按鈕上還能顯示倒計(jì)時(shí)

預(yù)想的效果圖:

這是微信公眾平臺上的代碼

function E() {
var e = $("#mobile"), t = (new Date).getTime(), n = Math.floor((t - b) / 1e3);
g && clearTimeout(g), n >= 60 ? (e.prop("readonly", !1), y = !0, $("#sendmobile").html("發(fā)送驗(yàn)證碼").attr("disabled", !1).removeClass("btn_disabled")) : (e.prop("readonly", !0), y = !1, $("#sendmobile").attr("disabled", !0).addClass("btn_disabled").html("%s秒后可重發(fā)".sprintf(60 - n)), g = setTimeout(E, 1e3));
}
function S() {
function e() {
if (!y) return;
var e = $.trim(n.val());
l.mobile(e) ? t.attr("disabled", !1).removeClass("btn_disabled") : t.attr("disabled", !0).addClass("btn_disabled");
}
var t = $("#sendmobile"), n = $("#mobile");
n.keyup(e).blur(e), e(), t.click(function() {
var e;
t.attr("disabled") !== "disabled" && (e = "+86" + $.trim(n.val()), b = (new Date).getTime(), E(), o.post({
url: w ? "/cgi-bin/formbyskey" : "/acct/formbyticket",
data: {
form: "mobile",
action: "set",
f: "json",
mobile: e
},
mask: !1
}, function(e) {
var t = e.BaseResp.Ret;
if (t == 0) u.suc("驗(yàn)證碼已經(jīng)發(fā)送"); else {
switch (t) {
case -13:
u.err("登錄超時(shí),請重新登錄");
break;
case -35:
u.err("該手機(jī)已經(jīng)登記過2次,請使用別的手機(jī)號進(jìn)行用戶信息登記");
break;
default:
u.err("驗(yàn)證碼發(fā)送失敗");
}
b = 0;
}
}));
});
}

這段代碼小編就是不知道怎么才能調(diào)用到自己的代碼上來,經(jīng)過高人指點(diǎn)有了一些頭尋。

高人的解題思路:如果嚴(yán)格的話,這個(gè)還要結(jié)合后臺獲取時(shí)間的,要不然別人刷新一下就行了。
                            如果不嚴(yán)格,用個(gè)cookie也可以。

<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script src="http://yukon12345.com/yukon12345.com/js/jquery.cookie.js"></script>
<script>
 time1=$.cookie("time1")||60;
 time2=$.cookie("time2")||60;
 dis1=$.cookie("dis1")
 dis2=$.cookie("dis2")
 function countDown($obj){

 var time;
 if($obj.attr("id")=="b1")
 {
 time=--time1;
 $.cookie("time1",time,{"expires":1});
 if(time<=0){
 time1=60;
 $obj[0].disabled=!$obj[0].disabled
 clearInterval(inter1)
 $obj.text("點(diǎn)擊發(fā)送")
 $.cookie("dis1","")
 return
 }
 }
 if($obj.attr("id")=="b2")
 { time=--time2;
 $.cookie("time2",time,{"expires":1});
 if(time<=0){
 time1=60;
 $obj[0].disabled=!$obj[0].disabled
 clearInterval(inter2)
 $obj.text("點(diǎn)擊發(fā)送")
 $.cookie("dis2","")
 return
 }
 }

 $obj.text(time+"秒后重新發(fā)送")

 }

 $(function(){
 if(dis1="dis"){
 $("#b1")[0].disabled='disabled'
 inter1=setInterval(function(){countDown($("#b1"))},1000)
 }
 if(dis2="dis"){
 $("#b2")[0].disabled='disabled'
 inter2=setInterval(function(){countDown($("#b2"))},1000)
 }
$(".cd").bind("click",function(){
 $this=$(this);
 //沒有被禁用時(shí)禁用并執(zhí)行倒計(jì)時(shí)
 if(!$this[0].disabled){
 $this[0].disabled='disabled';
 if($this.attr("id")=="b1"){
 $.cookie("dis1","dis",{"expires":1})
 inter1=setInterval(function(){countDown($this)},1000)
 }
 if($this.attr("id")=="b2"){
 $.cookie("dis2","dis",{"expires":1})
 inter2=setInterval(function(){countDown($this)},1000)
 }

 }
})

})
</script>

<button id="b1" class="cd" >點(diǎn)擊發(fā)送</button><br>
<button id="b2" class="cd" >點(diǎn)擊發(fā)送</button><br>

更多關(guān)于倒計(jì)時(shí)的文章請查看專題: 《倒計(jì)時(shí)功能》

大家通過這三個(gè)例子講解有沒有點(diǎn)思路了,那就動手實(shí)現(xiàn)一下吧,希望對大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • D3.js進(jìn)階系列之CSV表格文件的讀取詳解

    D3.js進(jìn)階系列之CSV表格文件的讀取詳解

    D3.js支持從外部讀取數(shù)據(jù)進(jìn)行圖形交互(Loading External Resources),支持的格式有CSV、txt、Html、tsv、xml文本文件和JSON XML數(shù)據(jù)結(jié)構(gòu),下面這篇文章主要給大家介紹了D3.js中CSV表格文件讀取的相關(guān)資料,需要的朋友可以參考下。
    2017-06-06
  • layui 表格的屬性的顯示轉(zhuǎn)換方法

    layui 表格的屬性的顯示轉(zhuǎn)換方法

    今天小編就為大家分享一篇layui 表格的屬性的顯示轉(zhuǎn)換方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 基于JavaScript繪制動態(tài)花束的示例代碼

    基于JavaScript繪制動態(tài)花束的示例代碼

    p5.js 是一個(gè)JavaScript的函數(shù)庫,它在制作之初就和Processing有同樣的目標(biāo)。本文將利用p5.js 制作出一束動態(tài)花束,感興趣的可以嘗試一下
    2022-06-06
  • ExpressJS使用express-ws的實(shí)例詳解

    ExpressJS使用express-ws的實(shí)例詳解

    這篇文章主要介紹了ExpressJS使用express-ws的實(shí)例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • 純 JS 實(shí)現(xiàn)放大縮小拖拽功能(完整代碼)

    純 JS 實(shí)現(xiàn)放大縮小拖拽功能(完整代碼)

    這篇文章主要介紹了純js實(shí)現(xiàn)放大縮小拖拽功能,文中給大家提到了在開發(fā)過程中遇到的一些問題及解決方法,需要的朋友可以參考下
    2019-11-11
  • 動態(tài)添加刪除表格行的js實(shí)現(xiàn)代碼

    動態(tài)添加刪除表格行的js實(shí)現(xiàn)代碼

    本篇文章主要是對動態(tài)添加刪除表格行的js實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-02-02
  • Bootstrap精簡教程

    Bootstrap精簡教程

    Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它簡潔靈活,使得 Web開發(fā)更加快捷。本文給大家分享Bootstrap精簡教程,對Bootstrap精簡教程感興趣的朋友一起學(xué)習(xí)
    2015-11-11
  • 微信企業(yè)號開發(fā)之微信考勤Cookies的使用

    微信企業(yè)號開發(fā)之微信考勤Cookies的使用

    使用微信考勤,每次使用微信企業(yè)號開發(fā):微信用戶信息和web網(wǎng)頁的session的關(guān)系這個(gè)里邊的方法,調(diào)用微信的接口,有點(diǎn)慢,微信官方也推薦使用Cookies,但如何使用Cookies,自己卻一直沒有搞清楚。下面小編幫大家解決難題,需要的朋友可以參考下
    2015-09-09
  • Bootstrap布局之柵格系統(tǒng)學(xué)習(xí)筆記

    Bootstrap布局之柵格系統(tǒng)學(xué)習(xí)筆記

    這篇文章主要為大家詳細(xì)介紹了Bootstrap布局之柵格系統(tǒng)的學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • JavaScript進(jìn)制數(shù)之間的互相轉(zhuǎn)換

    JavaScript進(jìn)制數(shù)之間的互相轉(zhuǎn)換

    這篇文章主要介紹了JavaScript進(jìn)制數(shù)之間的互相轉(zhuǎn)換,進(jìn)制轉(zhuǎn)換是人們利用符號來計(jì)數(shù)的方法,下文基于JavaScript實(shí)現(xiàn)進(jìn)制數(shù)之間的轉(zhuǎn)換,有一定的知識性參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05

最新評論