9

无法弄清楚如何为 ajax 加载的 recaptcha 设置主题。下面的代码不起作用。
来自谷歌验证码

看到这篇文章Recaptcha ajax API custom theme not working,但我肯定在 localhost 中查看,recaptcha 工作正常,只是没有改变主题。

有人对如何使白色主题起作用有建议吗?

    <script type='text/javascript'>
        var RecaptchaOptions = {
            theme : 'white'
         };
    </script>
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" height="300" width="500" frameborder="0"></iframe><br />
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
      </noscript>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content");
        });

    });
    </script>
4

4 回答 4

5

@jhanifen:我在使用http://wiki.recaptcha.net/index.php/Installation中的大部分代码后让它工作了,试试这个——

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    </head>

    <body>

    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {
                Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", 
                "recaptcha_content",
                {
                    theme: "white", 
                    callback: Recaptcha.focus_response_field
                }
            );
        });
    });
    </script>

    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" height="300" width="500" frameborder="0"></iframe><br />
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
      </noscript>
    </div>

    </body>
</html>
于 2011-03-14T20:04:55.290 回答
4

我看起来不像您正在添加您设置的选项RecapthcaOptions。尝试更改为:

$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
        function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content", RecaptchaOptions);
});

请参阅文档,传递给该.create()方法的第三个选项是选项。您正在函数外部设置一个变量来设置选项,但不包括它们。

于 2011-03-14T20:09:27.630 回答
1

首先,您的密钥无效或错误,或者您希望将其张贴在这里 :D 如果不想要。尝试获得一个新的,也许使它成为一个全局的(可能会影响本地主机的东西)。或者在您指定的域上上传并测试代码。

此片段适用于我的全局公钥,我直接在创建时设置主题

<html>
<head>
<title>recaptcha test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<body>    
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=publickey" height="300" width="500" frameborder="0"></iframe><br />
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
      </noscript>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        Recaptcha.create("publickey",
                         "recaptcha_content", {
                             theme: "white",
                             callback: Recaptcha.focus_response_field
        });
    });
    </script>   
</body>
</html>
于 2011-03-14T20:33:28.900 回答
0

采用奥卡姆剃刀法,您能否验证设置主题的脚本是否位于表单元素之前。如文档中多次所述,脚本在表单元素内部或之后不起作用。

于 2011-03-14T20:08:46.517 回答