效果如图点击时候 倒计时 结束 之后可以发送
代码如下
我按顺序 写 看下 html 点击发送的那个按钮
1.点击事件触发
$("#mobile_code").click(function(){ var contacts_phone=123456465; send_mobile_code(contacts_phone, $(this)); })
调用 send_mobile_code 方法
2.方法 如下
function send_mobile_code(mobileCodeObj, sendButton) { countdown(sendButton); //调用按钮 让它倒计时 显示 console.log('发送了'); return false; var url = 'apply.php'; $.post(url, { act: 'send_mobile_code', mobile_code:mobileCodeObj, }, function(result) { if (result == 'ok') { //倒计时 countdown(sendButton); } else { alert(result); } }, 'text'); }
3. countdown 方法 如下
function countdown(obj, msg) { if (wait == 0) { obj.removeAttr("disabled"); obj.html(msg); wait = 60; } else { if (msg == undefined || msg == null) { msg = obj.html(); } obj.attr("disabled", "disabled"); obj.html(wait + "秒后重新获取"); wait--; setTimeout(function() { countdown(obj, msg) }, 1000) } }这里面有个坑 就是 obj.html这个
我这个标签 是a 标签所以用的 html 要是 input的 要用 val