recaptcha.destroy()在自定义主题中不起作用

时间:2013-10-02 15:10:22

标签: javascript jquery css django recaptcha

我在一个页面中使用了两个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,并且未在<div id="studentcaptcha" or "teachcaptcha">...</div> destroy中放置任何自定义 html ( )效果最好但是当我使用custom主题并在div上放置我自己的html时它根本不起作用。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我弄清楚为什么Recaptcha.destroy()不会销毁旧的验证码...这是因为destroy()是为非自定义验证码主题设计的。

在它的定义中,它有:

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

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