js图形验证码插件gVerify
2017-09-09 本文已影响0人
李佳明先生
话不多说,上图。

- 首先,要准备一个容器(dom)来放canvas。
<div style="float: left;" style="width: 80px;height: 27px;" id="img"></div>
- js代码(初始化)
var verifyCode = new GVerify("img");
- 根据需求写逻辑代码
function preventDefa(e){
if(window.event){
//IE中阻止函数器默认动作的方式
window.event.returnValue = false;
}
else{
//阻止默认浏览器动作(W3C)
e.preventDefault();
}
}
$('.submit input').on('click',function(e){
if(!verifyCode.validate($('#validate').val())){
var str='<div id="Verrors" style="font-size: 14px;font-family:微软雅黑;color: red;">验证码不正确</div>';
$('.validate .errors').html('');
$('.validate .errors').append(str);
preventDefa(e);
}
})