一,简单框架
/*
验证码的获取
*/
btn_getYZM_event:
function(){
var c=this.counttime(this)
},
//这里的that,this常常会忘记写,然后会出现函数没有定义的错误。
counttime:
function(that){
setTimeout(
function () {
console.log(
"获取验证码。");
var c = that.counttime(that)//自己调用自己
},
1000)
//延迟时间 这里是1秒
},
二,完善后
/*
验证码的获取
*/
btn_getYZM_event:
function(){
var c=
this.counttime(
this)
},
counttime:
function(that){
setTimeout(
function () {
that.setData({
second: that.data.second -
1
})
if (that.data.second >
0) {
var c = that.counttime(that)
that.setData({
btn_regiter_txt: that.data.second
})
}
else {
that.setData({
btn_getYZM_event:
"btn_getYZM_event",
btn_regiter_txt:
"获 取",
second:
60,
})
}
},
1000)
//延迟时间 这里是1秒
},