简体   繁体   English

如果用户 select 验证码,如何删除验证码旁边的验证错误

[英]How to remove a validation error beside captcha if the user select the captcha

I am working on an asp.net MVC core web application, and i added a captcha as follow:-我正在开发一个 asp.net MVC 核心 web 应用程序,我添加了如下验证码:-

<div class="form-group">
                        <div class="col-md-2"></div>
                        <div class="col-md-10">
                            <span class="msg-error error"></span>
                            <div id="recaptcha" class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="@ViewData["ReCaptchaKey"]"></div>
                        </div>
                    </div>

also i added the following javascript validation to force a required on the captcha:-我还添加了以下 javascript 验证以强制验证验证码:-

$('#getmyestimate').click(function () {
               
                var $captcha = $('#recaptcha'),
                    response = grecaptcha.getResponse();

                if (response.length === 0) {
                    $('.msg-error').text("reCAPTCHA is mandatory");
                    if (!$captcha.hasClass("error")) {
                        $captcha.addClass("error");
                    }
                } else {
                    $('.msg-error').text('');
                    $captcha.removeClass("error");
                    alert('reCAPTCHA marked');
                }
            })

as follow:-如下:-

在此处输入图像描述

but what i am trying to do, is that once the user select the captcha to remove the validation error (if any),, so can anyone advice how i can do so?但我想做的是,一旦用户 select 验证码删除验证错误(如果有的话),那么任何人都可以建议我怎么做?

You can hide inside your callback recaptchaCallback function that you have already added in data-callback attribute in the g-recaptcha class.您可以隐藏在您已经添加到g-recaptcha class 的data-callback属性中的回调recaptchaCallback function 中。

var recaptchaCallback = function() {
   $('#recaptcha').removeClass("error");
   ... //Any other code in the callback
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM