clean.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. (function($) {
  2. $.fn.extend({
  3. addClear: function(options) {
  4. var options = $.extend({
  5. closeSymbol: "✖",
  6. color: "#CCC",
  7. top: 1,
  8. right: 4,
  9. returnFocus: true,
  10. showOnLoad: false,
  11. onClear: null
  12. }, options);
  13. $(this).wrap("<span style='position:relative;' class='add-clear-span'>");
  14. $(this).after("<a href='#clear'>" + options.closeSymbol + "</a>");
  15. $("a[href='#clear']").css({
  16. color: options.color,
  17. 'text-decoration': 'none',
  18. display: 'none',
  19. 'line-height': 1,
  20. overflow: 'hidden',
  21. position: 'absolute',
  22. right: options.right,
  23. top: options.top
  24. }, this);
  25. if ($(this).val().length >= 1 && options.showOnLoad === true) {
  26. $(this).siblings("a[href='#clear']").show();
  27. }
  28. $(this).keyup(function() {
  29. if ($(this).val().length >= 1) {
  30. $(this).siblings("a[href='#clear']").show();
  31. } else {
  32. $(this).siblings("a[href='#clear']").hide();
  33. }
  34. });
  35. $("a[href='#clear']").click(function() {
  36. $(this).siblings("input").val("");
  37. $(this).hide();
  38. if (options.returnFocus === true) {
  39. $(this).siblings("input").focus();
  40. }
  41. if (options.onClear) {
  42. options.onClear($(this).siblings("input"));
  43. }
  44. return false;
  45. });
  46. return this;
  47. }
  48. });
  49. }
  50. )(jQuery);
  51. var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
  52. var count = 60;
  53. var InterValObj1;
  54. var curCount1;
  55. function sendMessage1() {
  56. curCount1 = count;
  57. var phone = $.trim($('#phone1').val());
  58. if (!phoneReg.test(phone)) {
  59. alert("请输入有效的手机号码");
  60. return false;
  61. }
  62. $("#btnSendCode1").attr("disabled", "true");
  63. $("#btnSendCode1").val(+curCount1 + "秒再获取");
  64. $.get("http://f3dhion.nat.ipyingshe.com/user/send?phoneNumber=" + phone, function (res) {
  65. alert(res.data);
  66. })
  67. InterValObj1 = window.setInterval(SetRemainTime1, 1000);
  68. }
  69. function SetRemainTime1() {
  70. if (curCount1 == 0) {
  71. window.clearInterval(InterValObj1);
  72. $("#btnSendCode1").removeAttr("disabled");
  73. $("#btnSendCode1").val("重新发送");
  74. } else {
  75. curCount1--;
  76. $("#btnSendCode1").val(+curCount1 + "秒再获取");
  77. }
  78. }
  79. submitForm = function () {
  80. var flag = checkInput();
  81. if (flag) {
  82. var openid = getUrlParam("openid");
  83. $("#btnSendCode2").val(openid);
  84. $("#submit_form").submit();
  85. }
  86. }
  87. checkInput = function (){
  88. var a = true;
  89. var code = $("#code1").val;
  90. if ($.trim(code) === '') {
  91. a = false;
  92. alert("请输入验证码!");
  93. return a;
  94. }
  95. return a;
  96. }
  97. // 强制关注公众号,获取openid
  98. getCode = function () {
  99. if (sessionStorage.getItem("openid")&&sessionStorage.getItem("openid")!="undefined") {
  100. return false;
  101. }
  102. var code = getUrlParam('code') // 截取路径中的code,如果没有就去微信授权,如果已经获取到了就直接传code给后台获取openId
  103. var local = window.location.href;
  104. var APPID = 'wxf9360d70bc1406ee';
  105. if (code == null || code === '') {
  106. window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + APPID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_base&state=#wechat_redirect'
  107. } else {
  108. getOpenId(code) //把code传给后台获取用户信息
  109. }
  110. }
  111. //把code传给后台,得到openid
  112. getOpenId = function (code) {
  113. $.ajax({
  114. type: 'GET',
  115. dataType: 'text',
  116. url: 'http://f3dhion.nat.ipyingshe.com/oauth2?code='+code,
  117. success: function (res) {
  118. if (res.status == -1) {
  119. // 提示没有关注公众号 没有关注公众号跳转到关注公众号页面
  120. console.log('您还未关注公众号喔');
  121. //二维码弹窗
  122. $('.openPopup').click();
  123. return;
  124. } else {
  125. // 本地存储这个openid,并刷新页面
  126. sessionStorage.setItem("openid", res.data.openid);
  127. location.reload();
  128. }
  129. }
  130. });
  131. }
  132. //获取地址栏的参数
  133. getUrlParam= function (name) {
  134. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  135. var r = window.location.search.substr(1).match(reg);
  136. if (r != null) return unescape(r[2]); return null;
  137. }
  138. //页面执行调用
  139. getCode();
  140. window.scroll(0, 0);
  141. function binding() {
  142. alert(1)
  143. }