酷安网,耒阳,港币人民币-小二狗,互撩社区,男男女女单生信息,有趣的新闻

admin 2019-05-16 阅读:220

Vcode.js

开源地址:https://github.com/JofunLiang/Vcode.js

Vcode.js是一个根据原生Javascript开发的轻量级验证码生成插件

先来看几张效果图

  • 只包括数字

纯数字的验证码

  • 只包括字母

纯字母的验证码

  • 既包括数字又包括字母

一起包括数字和字母的验证码

  • 自定义的数据

自定义数据的验证码

使用方法(官网下载js文件):



//OR

// ES6 Modules or TypeScript
import vcode from 'Vcode'
// CommonJS
const vcode = require('Vcode')

Demo:


验证码:




function $(selector) {
return document.querySelector(selector);
}

//纯数字形式
var vcode = new Vcode({
el: "#demo .code",
count: 4,
fontSize: "60px",
type: "number",
spacing: 0
});

//纯字母形式
var vcode = new Vcode({
el: "#demo .code",
count: 4,
fontSize: "60px",
type: "letter",
spacing: 0
});

//字母数字混合形式
var vcode = new Vcode({
el: "#demo .code",
count: 4,
fontSize: "60px",
spacing: 0
});

//自定义数据形式
var vcode = new Vcode({
el: "#demo .code",
data:
"马蹄声回旋在竹林间千山外江湖边月光纵横云掠过山鹰的背脊他冷眼看繁花乱掷地无声",
count: 4,
fontSize: "42px",
spacing: 0
});
//重绘验证码
$("#demo button").onclick = function() {
vcode.onReset();
};

参数设置:

  • el(字符串,必填项) css选择器,用来填充验证码;
  • data(字符串,可选项)自定义验证码的数组来历;
  • count(整形数字,可选项,默许是4)生成验证码的字符长度;
  • type(字符串,可选项,默许是mix,数字字母混合形式)验证码类型;
  • fontSize(字符串,可选项)验证码的字体大小;
  • spacing(字符串,可选项,默许0)验证码字符间的距离;

验证码目标特点:

  • el(目标)验证码挂载的目标
  • code(字符串)验证码值
  • data(字符串)验证码数据源
  • count(数字)验证码长度
  • onReset(函数)从头生成验证码函数

MIT License

Copyright (c) 2018 jofunLiang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

同类插件

  • Vue验证码插件vue2-verify(https://github.com/mizuka-wu/vue2-verify)
  • 根据js和canvas的captcha.js (https://github.com/saucxs/captcha)