摘要:本文将带你了解微信小程序开发之+WEB使用JS实现注册倒计时功能,希望本文对大家学微信有所帮助。
本文将带你了解微信小程序开发之+WEB使用JS实现注册倒计时功能,希望本文对大家学微信有所帮助。
1、效果图: 2、页面仅仅利用了JS的相关功能,包含:wxml、js、wxss 2.1wxml页面代码:<text>绑定手机</text>
<form bindsubmit="bindMobile">
<view>
<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 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({
/**
* 页面的初始数据
*/
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页面代码:/* 发送验证码按钮隐藏,并展示倒数60s提示 */
.hide{
display: none;
}
.show{
display: block;
} 3、上面讲的是微信小程序的,那么我们一般web端或者移动端的应该是什么样呢?其实,方法都差不多,这里也贴出来仅供大家参考<!-- 这段代码(html)是从脚本之家挪过来的,信誉度应该是很高的,大家可以放心使用 -->
<script src="//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>
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号