所属分类:验证
第一步:引入生成验证码所需文件
<script src="js/jquery-1.11.0.min.js"></script> <script src="js/client_captcha.js" defer></script>
第二步:验证
document.addEventListener("DOMContentLoaded", function() { document.body.scrollTop; //force css repaint to ensure cssom is ready var timeout; //global timout variable that holds reference to timer var captcha = new $.Captcha({ onFailure: function() { $(".captcha-chat .wrong").show({ duration: 30, done: function() { var that = this; clearTimeout(timeout); $(this).removeClass("shake"); $(this).css("animation"); //Browser Reflow(repaint?): hacky way to ensure removal of css properties after removeclass $(this).addClass("shake"); var time = parseFloat($(this).css("animation-duration")) * 1000; timeout = setTimeout(function() { $(that).removeClass("shake"); }, time); } }); }, onSuccess: function() { alert("验证码输入成功!"); } }); captcha.generate(); });