register.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const btn_code = document.getElementById('btn-code')
  2. let timer
  3. let current // 剩余多少秒
  4. let isWating = false // 是否正在倒计时
  5. // 获取验证码点击事件
  6. btn_code.onclick = () => {
  7. if (isWating) return
  8. isWating = true
  9. clearInterval(timer)
  10. current = 60
  11. timer = setInterval(() => {
  12. current--
  13. btn_code.innerText = current
  14. if (current <= 0) {
  15. isWating = false
  16. btn_code.innerText = '重新获取'
  17. clearInterval(timer)
  18. }
  19. }, 1000)
  20. }
  21. // 显示隐藏密码
  22. const btn_password = document.getElementById('btn-password')
  23. const password = document.getElementById('password')
  24. btn_password.onclick = () => {
  25. if (password.type === 'password') {
  26. password.type = 'text'
  27. } else {
  28. password.type = 'password'
  29. }
  30. }
  31. // 提交按钮事件
  32. function checkForm() {
  33. const phoneVal = document.getElementById('phone').value
  34. const validVal = document.getElementById('valid').value
  35. const passwordVal = document.getElementById('password').value
  36. const protocol = document.getElementById('chk')
  37. if (!protocol.checked) {
  38. const res = confirm('注册即同意用户协议和隐私协议,确定将自动勾选')
  39. if (res) protocol.checked = true
  40. }
  41. if (phoneVal && validVal && passwordVal) {
  42. if (checkPhone(phoneVal)) {
  43. window.location.href="download.html";
  44. } else {
  45. alert('请填写正确的手机号')
  46. }
  47. } else {
  48. alert('请输入内容!')
  49. }
  50. return false
  51. }
  52. // 手机号检测
  53. function checkPhone(value){
  54. const reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/
  55. if(reg.test(value)) return true
  56. else return false
  57. }