溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微信小程序注冊60s倒計時功能 使用JS實現(xiàn)注冊60s倒計時功能

發(fā)布時間:2020-08-29 21:57:27 來源:腳本之家 閱讀:149 作者:Rolan 欄目:web開發(fā)

微信小程序+WEB使用JS實現(xiàn)注冊【60s】倒計時功能開發(fā)步驟:

1、效果圖: 

 微信小程序注冊60s倒計時功能 使用JS實現(xiàn)注冊60s倒計時功能

2、頁面僅僅利用了JS的相關功能,包含:wxml、js、wxss 

2.1wxml頁面代碼:

<text>綁定手機</text>
<form bindsubmit="bindMobile">
<view class="form_group">
  <text>手 機:</text>
  <input type="number" placeholder="請輸入手機號" maxlength="11" name="data_phone" value="" auto-focus="true" bindblur="blur_mobile" />
  <button type="button" class="{{is_show?'show':'hide'}}" bindtap="clickVerify">獲取驗證碼</button>
  <button type="button" class="{{is_show?'hide':'show'}}">重新發(fā)送{{last_time}}秒</button>
 </view>

<input type="number" placeholder="請輸入驗證碼" maxlength="6" name="data_verify" value=""/>
<button class="save_btn" form-type="submit">確認綁定</button>
</form>

2.2 js頁面代碼:

var countdown = 60;
var settime = function (that) {
 if (countdown == 0) {
 that.setData({
  is_show: true
 })
 countdown = 60;
 return;
 } else {
 that.setData({
  is_show:false,
  last_time:countdown
 })

 countdown--;
 }
 setTimeout(function () {
 settime(that)
 }
 , 1000)
}

Page({
 /**
 * 頁面的初始數(shù)據(jù)
 */
 data: {
 last_time:'',
 is_show:true
 },

 clickVerify:function(){
 var that = this;
 // 將獲取驗證碼按鈕隱藏60s,60s后再次顯示
  that.setData({
  is_show: (!that.data.is_show) //false
  })
  settime(that);
 }


})

2.3 wxss頁面代碼:

/* 發(fā)送驗證碼按鈕隱藏,并展示倒數(shù)60s提示 */
.hide{
 display: none;
}
.show{
 display: block;
} 

3、上面講的是微信小程序的,那么我們一般web端或者移動端的應該是什么樣呢?

其實,方法都差不多,這里也貼出來僅供大家參考

<!-- 這段代碼(html)是從億速云挪過來的,信譽度應該是很高的,大家可以放心使用 -->

<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript"> 
var countdown=60; 
function settime(obj) { 
if (countdown == 0) { 
obj.removeAttribute("disabled"); 
obj.value="免費獲取驗證碼"; 
countdown = 60; 
return;
} else { 
obj.setAttribute("disabled", true); 
obj.value="重新發(fā)送(" + countdown + ")"; 
countdown--; 
} 
setTimeout(function() { 
settime(obj) }
,1000) 
}
</script>
<body> 
<input type="button" id="btn" value="免費獲取驗證碼" onclick="settime(this)" /> 
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI