gift.js
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* 个人中心页-兑换礼品卡
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/02/22
*/
var $ = require('yoho.jquery');
var $giftError = $('.giftCardCode').find('.gift-error'),
$codeError = $('.captchaCode').find('.gift-error'),
reg = '',
code = '';
var Gift = {
suc1: false,
suc2: false,
suc3: false,
suc4: false,
bindGiftCardForm: function() {
$('#giftCardCode1').bind('blur keyup', function() {
reg = /^[0-9a-zA-Z]{4,4}$/;
if (!reg.test($('#giftCardCode1').val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
Gift.suc1 = false;
} else {
$giftError.html('');
$('#giftCardCode2').focus();
Gift.suc1 = true;
}
});
$('#giftCardCode2').bind('blur keyup', function() {
reg = /^[0-9a-zA-Z]{4,4}$/;
if (!reg.test($('#giftCardCode2').val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
Gift.suc2 = false;
} else {
$giftError.html('');
$('#giftCardCode3').focus();
Gift.suc2 = true;
}
});
$('#giftCardCode3').bind('blur keyup', function() {
reg = /^[0-9a-zA-Z]{4,4}$/;
if (!reg.test($('#giftCardCode3').val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
Gift.suc3 = false;
} else {
$giftError.html('');
Gift.suc3 = true;
}
});
$('#captchaCode').bind('blur keyup', function() {
code = $('#captchaCode').val();
if (code.length <= 0) {
$codeError.html('请输入验证码!');
Gift.suc4 = false;
} else {
$codeError.html('');
Gift.suc4 = true;
}
});
},
checkForm: function() {
if ($.trim($('#giftCardCode1').val()) === '' || $.trim($('#giftCardCode2').val()) === '' ||
$.trim($('#giftCardCode3').val()) === '') {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
return false;
}
if ($.trim($('#captchaCode').val()) === '') {
$codeError.html('请输入验证码!');
return false;
}
return true;
}
};
//更换验证码
function refreshCaptcha() {
var dt = new Date();
$('#imgcode').attr('src', '/home/gift/captcha?t=' + dt.getTime());
return false;
}
$('#sub-gift').on('click', function() {
if (Gift.checkForm()) {
$('#giftCardForm').submit();
} else {
return false;
}
});
$(document).on('click', '#imgcode,.check-img', function() {
refreshCaptcha();
});
$(function() {
refreshCaptcha();
Gift.bindGiftCardForm();
});