html代码 ~~~ <div class="weui_cell"> <div class="weui_cell_hd"><label class="weui_label">手机验证码</label></div> <div class="weui_cell_bd weui_cell_primary"> <input class="weui_input" type="number" placeholder="" name='phone_code'/> </div> <p class="bk_important bk_phone_code_send">发送验证码</p> <div class="weui_cell_ft"> </div> </div> </div> ~~~ js代码 ~~~ <script type="text/javascript"> var enable = true; $('.bk_phone_code_send').click(function(event) { if(enable == false) { return; } var phone = $('input[name=phone]').val(); // 手机号不为空 if(phone == '') { $('.bk_toptips').show(); $('.bk_toptips span').html('请输入手机号'); setTimeout(function() {$('.bk_toptips').hide();}, 2000); return; } // 手机号格式 if(phone.length != 11 || phone[0] != '1') { $('.bk_toptips').show(); $('.bk_toptips span').html('手机格式不正确'); setTimeout(function() {$('.bk_toptips').hide();}, 2000); return; } $(this).removeClass('bk_important'); $(this).addClass('bk_summary'); enable = false; var num = 60; var interval = window.setInterval(function() { $('.bk_phone_code_send').html(--num + 's 重新发送'); if(num == 0) { $('.bk_phone_code_send').removeClass('bk_summary'); $('.bk_phone_code_send').addClass('bk_important'); enable = true; window.clearInterval(interval); $('.bk_phone_code_send').html('重新发送'); } }, 1000); $.ajax({ url: '/service/validate_phone/send', dataType: 'json', cache: false, data: {phone: phone}, success: function(data) { if(data == null) { $('.bk_toptips').show(); $('.bk_toptips span').html('服务端错误'); setTimeout(function() {$('.bk_toptips').hide();}, 2000); return; } if(data.status != 0) { $('.bk_toptips').show(); $('.bk_toptips span').html(data.message); setTimeout(function() {$('.bk_toptips').hide();}, 2000); return; } $('.bk_toptips').show(); $('.bk_toptips span').html('发送成功'); setTimeout(function() {$('.bk_toptips').hide();}, 2000); }, error: function(xhr, status, error) { console.log(xhr); console.log(status); console.log(error); } }); }); </script> ~~~