Javascript Canvas.fillText在第一次之后不工作

Javascript Canvas.fillText在第一次之后不工作,javascript,html,mobile,html5-canvas,Javascript,Html,Mobile,Html5 Canvas,我正在使用jCaptcha.js为我的应用程序生成验证码。当我完成注册和注销并尝试注册新acc后,它第一次完美地工作。画布不会打印任何显示为空白的内容&因此,它会循环运行,因为我设置了一个检查,以查看它是否为空白 if ($('.jCaptchaText')[0].toDataURL() != $('#blankCaptcha')[0].toDataURL()) isCaptchaBlank = false; jCaptcha.js ! function(t, a) { "functi

我正在使用jCaptcha.js为我的应用程序生成验证码。当我完成注册和注销并尝试注册新acc后,它第一次完美地工作。画布不会打印任何显示为空白的内容&因此,它会循环运行,因为我设置了一个检查,以查看它是否为空白

if ($('.jCaptchaText')[0].toDataURL() != $('#blankCaptcha')[0].toDataURL())
isCaptchaBlank = false;
jCaptcha.js

! function(t, a) {
    "function" == typeof define && define.amd ? define([], function() {
        return t.jCaptcha = a()
    }) : "object" == typeof module && module.exports ? module.exports = a() : t.jCaptcha = a()
}(this, function() {
    var t = function(t, a) {
            return "function" != typeof NodeList.prototype.forEach && (NodeList.prototype.forEach = Array.prototype.forEach), Object.keys(a).forEach(function(e) {
                t[e] = a[e]
            }), t
        },
        a = function() {
            n = Math.round(8 * Math.random()) + 1, c = Math.round(8 * Math.random()) + 1, i = n + c
        },
        e = function(t, a, e) {
            !e && t[0].insertAdjacentHTML("beforebegin", '<canvas class="jCaptchaText"></canvas>'), this.$captchaText = this.$captchaText || document.getElementsByClassName("jCaptchaText"), this.$jCaptchaTextContext = this.$jCaptchaTextContext || this.$captchaText[0].getContext("2d"), this.$captchaText[0].width = a.canvasWidth, this.$captchaText[0].height = a.canvasHeight, this.$jCaptchaTextContext.textBaseline = "top", this.$jCaptchaTextContext.font = a.canvasFontSize + " " + a.canvasFontFamily, this.$jCaptchaTextContext.textAlign = "left", this.$jCaptchaTextContext.fillStyle = a.canvasFillStyle, this.$jCaptchaTextContext.fillText(n + " + " + c + " " + a.requiredValue, 0, 0)
        },
        i = void 0,
        n = void 0,
        c = void 0,
        o = function(a) {
            this.options = a ? t(this.options, a) : this.options, this.init()
        };
    return o.prototype = {
        options: {
            el: "jCaptcha",
            requiredValue: "=",// vinaya20180820 - made required value text as "=". it was * originally.
            resetOnError: !0,
            focusOnError: !0,
            clearOnSubmit: !0,
            canvasWidth: 50,
            canvasHeight: 15,
            canvasFontSize: "15px",
            canvasFontFamily: "Arial",
            canvasFillStyle: "#fff",
            callback: null
        },
        init: function() {
            this.$captchaInput = document.getElementsByClassName(this.options.el), a(), e(this.$captchaInput, this.options)
        },
        validate: function() {
            this.callbackReceived = this.callbackReceived || "function" == typeof this.options.callback, this.$captchaInput[0].value != i ? (this.callbackReceived && this.options.callback("error", this.$captchaInput), !0 === this.options.resetOnError && this.reset(), !0 === this.options.focusOnError && this.$captchaInput[0].focus(), !0 === this.options.clearOnSubmit && (this.$captchaInput[0].value = "")) : (this.callbackReceived && this.options.callback("success", this.$captchaInput), !0 === this.options.clearOnSubmit && (this.$captchaInput[0].value = ""))
        },
        reset: function() {
            a(), e(this.$captchaInput, this.options, !0)
        }
    }, o
});

!函数(t,a){
“function”==typeof define&&define.amd?define([],function(){
返回t.jCaptcha=a()
}):“object”==typeof module&&module.exports?module.exports=a():t.jCaptcha=a()
}(这个,函数(){
var t=函数(t,a){
返回“function”!=typeof NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),Object.keys(a).forEach(function(e){
t[e]=a[e]
}),t
},
a=函数(){
n=Math.round(8*Math.random())+1,c=Math.round(8*Math.random())+1,i=n+c
},
e=函数(t,a,e){
!e&&t[0]。insertAdjacentHTML(“beforebegin”,“beforebegin”,“beforebegin”),this.$captchaText=this.$captchaText | | | document.getElementsByClassName(“jCaptchaText”),this.$jCaptchaText | this.$captchaText[0]。getContext(“2d”),this.$captchaText[0]。宽度=a.canvasWidth,this.$captchaText[0].height=a.canvasHeight,this.$jCaptchaTextContext.textBaseline=“top”,this.$jCaptchaTextContext.font=a.canvasFontSize+”“+a.canvasFontFamily,this.$jCaptchaTextContext.fillStyle=a.canvasFillStyle,this.$jCaptchaTextContext.fillText(n+“+”+c+”“+a.requiredValue,0,0)
},
i=无效0,
n=无效0,
c=无效0,
o=功能(a){
this.options=a?t(this.options,a):this.options,this.init()
};
返回o.prototype={
选项:{
el:“jCaptcha”,
requiredValue:“=”,//vinaya20180820-将required value文本设置为“=”,原来是*的。
重置者:0,
FocusOneError:!0,
clearOnSubmit:!0,
画布宽度:50,
画布高度:15,
画布字体大小:“15px”,
canvasFontFamily:“Arial”,
画布风格:“fff”,
回调:null
},
init:function(){
this.$captchaInput=document.getElementsByClassName(this.options.el)、a()、e(this.$captchaInput、this.options)
},
验证:函数(){
this.callbackReceived=this.callbackReceived | | |“function”==typeof this.options.callback,this.$captchaInput[0].value!=i?(this.callbackReceived&&this.options.focusOnError&&this.$captchaInput[0].focus(),!0==this.options.clearOnSubmit&&(this.$captchaInput[0].value=”“):(this.callbackReceived&&this.options.callback(“成功”,this.$captchaInput),!0==this.options.clearOnSubmit&&(this.$captchaInput[0].value=”“))
},
重置:函数(){
a(),e(this.$captchaInput,this.options,!0)
}
},o
});

我刚刚添加了一个
位置。当我再次重定向到登录页面(验证码初始化的地方)时,重新加载(true)
。这对我有用。不知道它是否有缓存问题或.filltext有问题,但重载似乎可以解决它。请告诉我是否有更好的解决方案