2013-10-02 26 views
1

我在一个页面中使用两个recaptcha,这个页面有两种形式供不同的用户使用。recaptcha.destroy()在自定义主题中不起作用

我使用自定义主题,使用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并且不要放任何自定义html<div id="studentcaptcha" or "teachcaptcha">...</div>破坏()最好,但它根本不工作时,我使用custom主题,并把我自己的HTML div

有什么建议吗?

回答

0

我想出了为什么Recaptcha.destroy()不会破坏旧的captcha ...这是因为destroy()是专为非自定义captcha主题。

在其确定指标,它具有:

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

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