html:
<div class="left_box lf">
<div class="menu">
<span style="color: #ccc;">忘記密碼</span>
</div>
<div class="content">
<!-- 登錄 -->
<div class="content_inner active" data-content="one">
<p>
<img src="images/pc_icon_telephone.png" alt=""/>
<input id="loginPhone" type="text" value="" placeholder="請輸入手機號"/>
</p>
<p style="margin-top: 10px;width:90%;overflow:hidden;margin-left:5%">
<input id="iputCode" type="text" placeholder="請輸入驗證碼" style="width:65%;padding-left:20px;float:left;">
<input type="button" id="obtain" value="獲取驗證碼" style="cursor: pointer;float:left;width:35%;padding-left: 0;color:#2C8FFF;background: none;">
</p>
<button id="nextStep" class="login">下一步</button>
</div>
</div>
</div>
js:
$(function(){
//獲取驗證碼
$('#obtain').click(function(){
var ipone = isIpone($('#loginPhone').val());//手機號驗證
var loginPhone = document.getElementById('loginPhone').value;
var Weburl = G_WEBBASE + 'rcall.jsp?sytid=CHIS&mwid=GzyyInterface02&funcid=PhoneJY&userid='+loginPhone;
if(ipone == true){
//請求
try {
$.ajax({
url: Weburl,
async: false,
timeout: 8000,
type: 'POST',
success: function(result) {
try {
result = result.trim();
result = result.replace(/\n/g, '');//此處做去空格處理
console.log(result)
if(result == '0'){
alert('該號碼未注冊');
}else {
alert("驗證碼已發送,請注意查收");
time();//調用
document.getElementById('iputCode').setAttribute('class',result);//讓該元素添加calss
}
} catch(e) {
// alert("接口錯誤,請聯系客服");
}
},
error: function(xhr, status, error) {
if(status == "error")
alert('請檢查網絡連接');
}
});
} catch(error) {
alert("請檢查網絡連接");
}
}
})
//下一步
$('#nextStep').click(function(){
var ipone = isIpone($('#loginPhone').val());//手機號驗證
var loginPhone = document.getElementById('loginPhone').value;// 獲取用戶手機號碼
if(ipone != true){
return;
}
var yzm = verify();//此處調用驗證方法
if(yzm != true){
return;
}
if(ipone == true && yzm == true) {
// 下一步跳轉設置密碼頁面
window.open('resetPassword.html?iphone='+loginPhone)
}
})
})
/**
* 點擊獲取驗證碼后顯示倒數時間
*/
var wait = 60;// 定義短信發送倒計時時間
function time(){
document.getElementById('obtain').disabled = false; //讓按鈕可以點擊
if(wait == 0) {
document.getElementById('obtain').removeAttribute("disabled"); // 控制按鈕可點擊
document.getElementById('obtain').value = "獲取驗證碼";
document.getElementById('obtain').style.color = '#2C8FFF';
wait = 60; //還原倒計時
}else{
document.getElementById('obtain').setAttribute("disabled", true);//控制按鈕不可點擊
document.getElementById('obtain').value = "重新發送(" + wait + ")";
document.getElementById('obtain').style.color = '#C0BBBB';
wait--;
setTimeout('time()', 1000) //循環調用
}
}
/**
* 驗證驗證碼是否正確
*/
function verify() {
var yzm = document.getElementById('iputCode').value; // 獲取注冊用戶填寫的驗證碼
var yzmtwo = document.getElementById('iputCode').className; // 系統發送的驗證碼
if (yzm == ""){
alert("驗證碼不能為空");
return false;
}else if (yzm != yzmtwo){
alert("驗證碼錯誤,請重新輸入!");
eturn false;
}
return true;
}
//手機號驗證
function isIpone(ipone) {
var reg = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))[0-9]{8}$/;
if(ipone != "") {
if(reg.test(ipone) === false) {
alert("手機號輸入不合法");
return false;
}
}else{
alert("手機號不能為空");
return false;
}
return true;
}