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:
<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'}}">重新发送{{last_time}}秒</button> </view> <input type="number" placeholder="请输入验证码" maxlength="6" name="data_verify" value=""/> <button class="save_btn" form-type="submit">确认绑定</button> </form>
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:'', is_show:true }, clickVerify:function(){ var that = this; // 将获取验证码按钮隐藏60s,60s后再次显示 that.setData({ is_show: (!that.data.is_show) //false }) settime(that); } })
/* 发送验证码按钮隐藏,并展示倒数60s提示 */ .hide{ display: none; } .show{ display: block; }
<!-- 这段代码(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!