验证码是否相等

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .input-code {
            outline: none;
        }

    </style>
</head>
<body>


<div>
    <input type="text" class="input-code" placeholder="验证码">
    <span class="code"  title='点击切换'></span>

</div>

</body>
</html>

<script src="https://code.jquery.com/jquery-3.3.1.min.js "></script>
<script src="jquery.code.js"></script>
<script>
    $(function () {
        $('.code').createCode({
            len:4
        });
    });
    $('.input-code').blur(function () {
        if($(this).val().toLowerCase()!==$('.code').children('input').val().toLowerCase()){
            alert('验证码不正确')
        }else{
            alert('验证通过')
        }
    })
</script>



jQuery.code.js

 

 

/**
 * Created by duanhailin on 2018/06/21.
 */
;(function ($) {
    function createCode(dom, config) {
        var _this = this;
        _this.config = config
        _this.codeList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
        _this.color = ['#e3730f', '#2ae3e0', '#c317e3', '#0e935f','#e30d65', '#3c8b36', '#74675a', '#654321','#123345', '#135784', '#169b9a', '#02468a'];
        _this.bgColorList = ['#b1b1b1', '#e3d7cc', '#d0d9f9', '#f8f2d6'];
        _this.bgColor = '';
        _this.code = '';
        if (_this.config) {
            _this.codeLen = _this.config.len || 4;
        } else {
            _this.codeLen = 4;
        }
        var html = '';
        var deg = 0;
        for (i = 0; i < _this.codeLen; i++) {
            var index = Math.floor(Math.random() * _this.codeList.length);
            var idx = Math.floor(Math.random() * _this.color.length);
            var bgIdx = Math.floor(Math.random() * _this.bgColorList.length);
            if (index % 2 == 0) {
                deg = index + Math.floor(Math.random() * idx)
            } else {
                deg = -(index + Math.floor(Math.random() * idx))
            }
            html += '<span style="padding:0 2px;color:' + _this.color[idx] + ';display:inline-block;transform:rotate(' + deg + 'deg);">' + _this.codeList[index] + '</span>';
            _this.code += _this.codeList[index];
            _this.bgColor = _this.bgColorList[bgIdx]

        }
        html += '<input placeholder="" value="'+_this.code+'" type="hidden">';
        $(dom).css({
            width: _this.codeLen * 20 + 'px',
            padding: '1px',
            textAlign: 'center',
            display: 'inline-block',
            backgroundColor: _this.bgColor,
            cursor: "pointer",
            opacity: .6
        });
        $(dom).empty().append(html);
    }

    $.fn.createCode = function (cfg) {
        var _this = this;
        createCode(_this, cfg);
        $(_this).click(function () {
            createCode(_this, cfg);
        });
    }
})(jQuery);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值