|
正在加载验证码......
请先拖动验证码到相应位置
function RndNum(n) {
var rnd = "";
for (var i = 0; i < n; i++)
rnd += Math.floor(Math.random() * 10);
return rnd;
}
var xxx = RndNum(3);
var handler = function (captchaObj) {
$("#btn_getcode").click(function (e) {
onblurMobile();
var validate = captchaObj.getValidate();
if (!validate) {
$("#notice")[0].className = "show";
setTimeout(function () {
$("#notice")[0].className = "hide";
}, 2000);
e.preventDefault();
}
else {
$("#hcaptcha").val("1");
showtime(60);
SendMobileCode(validate);
}
});
// 将验证码加到id为captcha的元素里
captchaObj.appendTo("#captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
});
};
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: "/tools/getcaptcha.aspx?t=" + xxx + "&mobile=" + $("#txt_mobile").val() + "",
type: "get",
dataType: "json", // 使用jsonp格式
success: function (data) {
// 使用initGeetest接口
// 参数1:配置参数,与创建Geetest实例时接受的参数一致
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
product: "float", // 产品形式
offline: !data.success
}, handler);
}
});
function SendMobileCode(validate) {
des = "tb";
PageMethods.SendMobileCode($("#txt_mobile").val(), validate.geetest_challenge, validate.geetest_validate, validate.geetest_seccode, funReady, funError);
}
function funReady(result) {
result = JSON.parse(result);
if (result.data == 1) {
$("#div_captcha").val("验证码已发送!")
}
else {
alert(result.data);
}
}
function funError(err) {
alert("Error:" + err._message);
}
function showtime(t) {
document.getElementById("btn_getcode").disabled = true;
for (i = 1; i <= t; i++) {
window.setTimeout("update_p(" + i + "," + t + ")", i * 1000);
}
}
function update_p(num, t) {
if (num == t) {
document.getElementById("btn_getcode").value = " 重新发送 ";
document.getElementById("btn_getcode").disabled = false;
}
else {
printnr = t - num;
document.getElementById("btn_getcode").value = " (" + printnr + ")秒后重新发送";
}
}
function checkCode() {
PageMethods.checkCode($("#txt_mobile").val(), $("#txt_code").val(), funReady2, funError2);
}
function funReady2(result) {
if (result == "1") {
$("#div_code").html("正确!")
}
else {
$("#div_code").html("验证码错误!")
return false;
}
}
function funError2(err) {
alert("Error:" + err._message);
}
|
|
|
|
|