一個頁面需要兩個驗證碼,使用同一個驗證碼調用兩次會導致有前一個失效。那么我們需要創(chuàng)建不同的兩個驗證碼,分別做驗證。
<script src="captcha.js?appid=XXX&plural=1" id="KgCaptcha1"></script>
<script src="captcha.js?appid=XXX&plural=2" id="KgCaptcha2"></script>
<script type="text/javascript">
// 第一個驗證碼
kg1.captcha({
// 綁定元素,驗證框顯示區(qū)域
bind: "#captchaBox1",
// 驗證成功事務處理
success: function(e) {
console.log(e);
},
// 驗證失敗事務處理
failure: function(e) {
console.log(e);
},
// 點擊刷新按鈕時觸發(fā)
refresh: function(e) {
console.log(e);
}
});
// 第二個驗證碼
kg2.captcha({
// 綁定元素,驗證框顯示區(qū)域
bind: "#captchaBox2",
// 驗證成功事務處理
success: function(e) {
console.log(e);
},
// 驗證失敗事務處理
failure: function(e) {
console.log(e);
},
// 點擊刷新按鈕時觸發(fā)
refresh: function(e) {
console.log(e);
}
});
</script>
<!-- 第一個驗證碼 -->
<div id="captchaBox1"></div>
<!-- 第二個驗證碼 -->
<div id="captchaBox2"></div>
SDK開源地址:https://github.com/KgCaptcha,順便做了一個演示:https://www.kgcaptcha.com/demo/
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號