search
HomeWeChat AppletMini Program DevelopmentWeChat applet uses JS to implement the 60s countdown function for registration

This article mainly introduces the 60s countdown function for WeChat Mini Program registration, and the use of JS to implement the 60s countdown function for registration. It has certain reference value. Interested friends can refer to

WeChat Mini Program +WEB uses JS to implement the registration [60s] countdown function development steps:

1. Rendering:


##2. The page is only Utilizes the related functions of JS, including: wxml, js, wxss

2.1wxml page code:

<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?&#39;show&#39;:&#39;hide&#39;}}" bindtap="clickVerify">获取验证码</button>
    <button type="button" class="{{is_show?&#39;hide&#39;:&#39;show&#39;}}">重新发送{{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 page code:

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({
 /**
  * 页面的初始数据
  */
 data: {
  last_time:&#39;&#39;,
  is_show:true
 },

 clickVerify:function(){
  var that = this;
 // 将获取验证码按钮隐藏60s,60s后再次显示
   that.setData({
    is_show: (!that.data.is_show)  //false
   })
   settime(that);
 }


})

2.3 wxss page code:

/* 发送验证码按钮隐藏,并展示倒数60s提示 */
.hide{
 display: none;
}
.show{
 display: block;
}

3. The above is about the WeChat applet, so what should our general web or mobile version look like?


Actually, the methods are similar, and they are posted here for your reference only

<!-- 这段代码(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="重新发送(" + countdown + ")"; 
countdown--; 
} 
setTimeout(function() { 
settime(obj) }
,1000) 
}
</script>
<body> 
<input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" /> 
</body>
</html>

The above is the detailed content of WeChat applet uses JS to implement the 60s countdown function for registration. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software