<script type="text/javascript" src="__PUBLIC__/home/js/static/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/plugin/jquery.validate.min.js"></script>
<form action="" id="testform">
<input type="text" id="LOAN_NAME" placeholder="姓名" maxlength="5" class="fl" name="LOAN_NAME">
<div class="status"></div>
<input type="text" id="LOAN_PHONE_NUM" placeholder="电话号码" maxlength="11"
οnkeyup="value=value.replace(/[^\d]/g,'')" class="fl" name="LOAN_PHONE_NUM">
<input type="submit" id="cmt_loan" value="提 交" class="fl">
<div class="tip-error fl" id="ts_div" style="display: none">
<i class="img-jr-tip2"></i><span class="txt" id="ts_span"></span>
</div>
</form>
$("#testform").validate({
rules: {
LOAN_NAME: {
required: true
},
LOAN_PHONE_NUM: {
required: true
}
},
messages: {
LOAN_NAME: {
required: '请输入真实的姓名'
},
LOAN_PHONE_NUM: {
required: '请输入11位以内的号码'
}
},
submitHandler: function () {
if ($("#testform").valid()) {
var formObj = new Object();
formObj['LOAN_NAME'] = $("#LOAN_NAME").val().trim();
formObj['LOAN_PHONE_NUM'] = $("#LOAN_PHONE_NUM").val().trim();
$.ajax({
url: "{:U('/Home/Index/loan_client')}",
type: "put",
data: {'formData': formObj},
async: false,
success: function (datas) {
if (datas.error_code == 2004) {
layer.alert('您的姓名和电话号码已经登记!', {
icon: 1,
title: false,
skin: 'success-pop'
})
} else if (datas.error_code == 3011) {
layer.alert('当前手机号码的用户已经登记!', {
icon: 1,
title: false,
skin: 'success-pop'
})
} else {
// 成功失败弹窗
layer.alert('提交成功', {
icon: 1,
title: false,
skin: 'success-pop'
})
}
$("#LOAN_NAME").val('');
$("#LOAN_PHONE_NUM").val('');
$("#ts_div").attr('style', 'display:none');
}
});
}
}
});