connect_sms.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. $(function() {
  2. $(document).off('click',"#btn_sms_captcha").on('click',"#btn_sms_captcha", function() {
  3. var type = $(this).attr('ds_type');//ds_type 1为注册 2为登录 3为找回密码
  4. var sms_mobile = $(this).parents("form").find("#sms_mobile").val();
  5. var target = this;
  6. if (sms_mobile.length == 11) {
  7. var ajaxurl = HOMESITEURL + '/Connectsms/get_captcha.html?type=' + type;
  8. ajaxurl += '&sms_mobile=' + sms_mobile;
  9. $.ajax({
  10. type: "GET",
  11. url: ajaxurl,
  12. async: false,
  13. success: function (rs) {
  14. if (rs == 'true') {
  15. layer.msg('短信动态码已发出');
  16. countdown(target,"获取手机验证码");
  17. } else {
  18. layer.msg(rs);
  19. }
  20. }
  21. });
  22. }else{
  23. layer.msg('请先输入正确手机号');
  24. }
  25. })
  26. })
  27. var wait = 60;
  28. function countdown(obj,msg) {
  29. obj = $(obj);
  30. if (wait <= 0) {
  31. obj.prop("disabled", false);
  32. obj.html(msg);
  33. wait = 60;
  34. } else {
  35. if (msg == undefined || msg == null) {
  36. msg = obj.html();
  37. }
  38. obj.prop("disabled", true);
  39. obj.html(wait + "秒后重新获取");
  40. wait--;
  41. setTimeout(function () {
  42. countdown(obj,msg)
  43. }, 1000)
  44. }
  45. }
  46. function check_captcha() {
  47. if ($("#sms_mobile").val().length == 11 && $("#sms_captcha").val().length == 6) {
  48. var ajaxurl = HOMESITEURL+'/Connectsms/check_captcha.html';
  49. ajaxurl += '&sms_captcha=' + $('#sms_captcha').val() + '&sms_mobile=' + $('#sms_mobile').val();
  50. $.ajax({
  51. type: "GET",
  52. url: ajaxurl,
  53. async: false,
  54. success: function(rs) {
  55. if (rs == 'true') {
  56. $.getScript(HOMESITEURL+'/Connectsms/register.html' + '?sms_mobile=' + $('#sms_mobile').val());
  57. $("#register_sms_form").show();
  58. $("#post_form").hide();
  59. } else {
  60. layer.msg(rs);
  61. }
  62. }
  63. });
  64. }
  65. }