-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
60 lines (59 loc) · 1.9 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jquery-captcha</title>
<style>
.captcha-box {
width: 800px;
margin: 0 auto;
}
#canvas {
border: 1px solid #cccccc;
}
</style>
</head>
<body>
<div class="captcha-box">
<canvas id="canvas"></canvas>
<button id="refresh">刷新</button>
<input name="code">
<button id="valid">校验</button>
</div>
<script src="https://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/jquery-captcha.min.js"></script>
<script>
// step-1
const captcha = new Captcha($('#canvas'), {
length: 6, // 校验码长度
width: 300, // canvas宽度
height: 80, // canvas高度
font: 'bold 23px 微软雅黑', // 文本字体样式
resourceType: 'aA0', // 资源类型:a-小写字母、A-大写字母、0-数字,可任意组合
resourceExtra: [], // 额外资源
clickRefresh: true, // 点击刷新
autoRefresh: true, // 调用校验接口后是否自动刷新(校验成功不会刷新)
caseSensitive: false, // 大小写是否敏感
});
$('#refresh').on('click', function() {
captcha.refresh();
});
$('#valid').on('click', function() {
const val = $('input[name="code"]').val();
if (val === "") {
alert("请输入验证码");
return
}
console.log("val:", val);
console.log("code:", captcha.getCode());
if (captcha.valid(val)) {
// success
alert('验证通过');
} else {
// failure
alert('验证码错误');
}
})
</script>
</body>
</html>