【问题标题】:recaptcha.destroy() does not work in custom themerecaptcha.destroy() 在自定义主题中不起作用
【发布时间】:2013-10-09 00:53:45
【问题描述】:

我在一个页面中使用了两个 recaptcha,该页面有两种形式供不同的用户使用。

我正在使用自定义主题来使用 AJAX API 创建验证码:

function showRecaptcha(element) {
    Recaptcha.create(
        'publice_key',
        element, {
            theme: 'custom',
            callback: Recaptcha.focus_response_field
        });
}

我以两种模式使用它:

$("#to-teach").click(function() {
        $("#sign-up-welcome").hide();
        teachForm();
        showRecaptcha('teachcaptcha');
        return false;
    });

还有一个

$("#to-student").click(function() {
            $("#sign-up-welcome").hide();
            studentForm();
            showRecaptcha('studentcaptcha');
            return false;
        });

teachForm() 是:

function teachForm() {
        Recaptcha.destroy('studentcaptcha');
        signup.show();
        signupTitle.text("Sign Up as a Teacher");
    }

和类似的销毁事件用作Recaptcha.destroy('teachcaptcha');

自定义验证码的html是:

<div id="teachcaptcha">
                <div id="recaptcha_image"></div>
                <div class="captcha-input-box">
                    <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" class="input-recaptcha" />
                    <a class="fontawesome-refresh" href="javascript:Recaptcha.reload()"></a>
                    <a class="fontawesome-headphones recaptcha_only_if_image" href="javascript:Recaptcha.switch_type('audio')"></a>
                    <a class="fontawesome-picture recaptcha_only_if_audio" href="javascript:Recaptcha.switch_type('image')"></a>
                    <a class="fontawesome-question" href="javascript:Recaptcha.showhelp()"></a>
                </div>
            </div>

对于studentcaptcha

也是如此

问题是,如果我使用 white 主题而不是 custom 并且不在 &lt;div id="studentcaptcha" or "teachcaptcha"&gt;...&lt;/div&gt; 中放置任何自定义 html,则 destroy() 有效最好但是当我使用custom 主题并将我自己的html 放在div 上时它根本不起作用。

有什么建议吗?

【问题讨论】:

    标签: javascript jquery css django recaptcha


    【解决方案1】:

    我知道为什么Recaptcha.destroy() 不会破坏旧的验证码...这是因为destroy() 是为非自定义验证码主题设计的。

    在它的定义中,它有:

    Recaptcha.widget&amp;&amp;("custom"!=Recaptcha.theme?Recaptcha.widget.innerHTML="":Recaptcha.widget.style.display="none",Recaptcha.widget=null) 所以当使用custom 主题时它不会完全删除验证码。

    解决方案是编写自定义销毁方法,使用jQuery(或JavaScript)手动删除验证码的html小部件。

    【讨论】:

      猜你喜欢
      • 2020-10-22
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多