JQuery源代码:信息已发出,60秒后重新发送
HTML源代码片断:
<!--短信验证码-->
<div class="vervode_main ovhide hide">
<div class="vercode_l fl">
<input type="number" style="border:1px solid #e1e1e1;" placeholder="短信验证码" name="code" value="" regexp="^[0-9]{4,6}$">
<div class="code_error hide">
<i class="iconfont icon-pc-tishi"></i>
<span>请输入正确验证码</span>
</div>
</div>
<div class="vercode_r">
<button type="button" class="" id="sendCode" onclick="getVerify1()">获取验证码</button>
<div class="send_again hide"><span>60</span>s后重新发送</div>
</div>
</div>
JQuery源代码片断:
<script>
var miao1 = 60;
var m1 = null;
var codeBtnObj1 = $("#sendCode");
var daojishi1 = function() {
clearInterval(m1);
if (miao1 == 0) {
codeBtnObj1.html('获取验证码');
miao1 = 60;
$("#sendCode").attr("onclick","getVerify1()");
} else {
miao1 = miao1 - 1;
codeBtnObj1.html(miao1 + 's后重新发送');
m1 = setInterval(daojishi1, 1000);
$("#sendCode").attr("onclick","getalert()");
}
};
function getalert() {
layer.alert('信息已发出,60秒后重新发送');
}
function getVerify1() {
var tel = $.trim( $("input[name=tel]").val() );
if(tel=='') {
layer.alert('请输入手机号');
return;
}
$.ajax({
url: "http://www.ithov.net/sendmsgcode",
type: "POST",
data: {phone: tel},
dataType: "json",
success: function (data) {
if (data.status == 1) {
daojishi1();
} else {
alert(data.msg);
}
}
});
}
function guanbi() {
$("#gray").hide();
$(".login").hide();
}
function showlogin(){
$("#gray").show();
$(".login").show();
}
</script>
手机号验证,动态监测手机号源代码片断:
<script>
/*手机号输入监控*/
function checkmobile(phone){
var myreg = /^1[3-9][0-9]{9}$/;
if(myreg.test(phone)){
return true;
}else{
return false;
}
}
//输入手机号时,动态监测手机号
$("input[name=tel]").on("keyup",function(){
if(checkmobile($(this).val())){
var phone=$(this).val();
$.ajax({
url: "/index.php/Index/checktel",
type: "POST",
data: {phone: phone},
dataType: "json",
success: function (data) {
if(data.status!=1){
if($(".vervode_main").hasClass("hide")){
$(".vervode_main").removeClass("hide");
}
}
}
});
}else{
$(".vervode_main").addClass("hide");
}
})
</script>