H5+JS生成验证码
JS代码,拷贝下来复制即可,不说太多,直接上代码
JS代码,拷贝下来复制即可,不说太多,直接上代码
!(function(window, document) {
function GVerify(options) {
this.options = {
id: "",
canvasId: "verifyCanvas",
width: "100",
height: "30",
type: "blend",
code: ""
}
if(Object.prototype.toString.call(options) == "[object Object]"){
for(var i in options) {
this.options[i] = options[i];
}
}else{
this.options.id = options;
}
this.options.numArr = "0,1,2,3,4,5,6,7,8,9".split(",");
this.options.letterArr = getAllLetter();
this._init();
this.refresh();
}
GVerify.prototype = {
/**版本号**/
version: '1.0.0',
/**初始化方法**/
_init: function() {
var con = document.getElementById(this.options.id);
var canvas = document.createElement("canvas");
this.options.width = con.offsetWidth > 0 ? con.offsetWidth : "100";
this.options.height = con.offsetHeight > 0 ? con.offsetHeight : "30";
canvas.id = this.options.