簡體   English   中英

用戶通過驗證后,刪除reCaptcha的HTML5自定義錯誤消息

[英]Remove HTML5 custom error message for reCaptcha after user passes validation

我正在嘗試基於以下答案: https : //stackoverflow.com/a/37048027

答案有效,但我想輸入自定義HTML5驗證錯誤消息,因此將javascript擴展為:

 window.onload = function() {
    var $recaptcha = document.querySelector('#g-recaptcha-response');
    if($recaptcha) {
        $recaptcha.setAttribute("required", "required");
        $recaptcha.setAttribute("oninvalid", "this.setCustomValidity('Please fill in the reCAPTCHA field.')");
        $recaptcha.setAttribute("oninput", "this.setCustomValidity('')");
    }
};

問題是,如果僅顯示一次驗證錯誤,則始終在之后顯示,並且永遠不會消失。 我嘗試添加oninput,onvalid和onchange,但是在最初顯示之后,似乎無法使錯誤消息消失。

您可以根據規范通過將novalidate添加到form元素來禁用HTML5表單驗證。

例如

<form action="..." onsubmit="check_if_capcha_is_filled" novalidate>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM