引用jquery库和jquery.code.js
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script> <script src="js/jquery.code.js"></script>
html
<input type="text" placeholder="验证码"> <span title='点击切换'></span>
js
$(function() {
// 自定义验证码个数
$('.code').createCode({
len: 6
});
});
// 前面输入框失去焦点验证
$('.input-code').blur(function() {
if ($(this).val().toLowerCase() != $('.code').children('input').val().toLowerCase()) {
alert('验证码不正确')
} else {
alert('验证通过')
}
})