const btn_code = document.getElementById('btn-code') let timer let current // 剩余多少秒 let isWating = false // 是否正在倒计时 // 获取验证码点击事件 btn_code.onclick = () => { if (isWating) return isWating = true clearInterval(timer) current = 60 timer = setInterval(() => { current-- btn_code.innerText = current if (current <= 0) { isWating = false btn_code.innerText = '重新获取' clearInterval(timer) } }, 1000) } // 显示隐藏密码 const btn_password = document.getElementById('btn-password') const password = document.getElementById('password') btn_password.onclick = () => { if (password.type === 'password') { password.type = 'text' } else { password.type = 'password' } } // 提交按钮事件 function checkForm() { const phoneVal = document.getElementById('phone').value const validVal = document.getElementById('valid').value const passwordVal = document.getElementById('password').value const protocol = document.getElementById('chk') if (!protocol.checked) { const res = confirm('注册即同意用户协议和隐私协议,确定将自动勾选') if (res) protocol.checked = true } if (phoneVal && validVal && passwordVal) { if (checkPhone(phoneVal)) { window.location.href="download.html"; } else { alert('请填写正确的手机号') } } else { alert('请输入内容!') } return false } // 手机号检测 function checkPhone(value){ 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}$/ if(reg.test(value)) return true else return false }