hCaptcha JavaScript API 呈现:无效容器 'null'

hCaptcha JavaScript API render: invalid container 'null'

我在 Opera 开发者控制台上收到此错误 <[hCaptcha] 渲染:容器无效 'null'.>。 我替换了我的站点密钥,它返回了无效的容器 null。

这是我的源代码。

<html>
    <head>
        <script src="https://hcaptcha.com/1/api.js?onload=yourFunction&render=explicit" async defer></script>
      <script type="text/javascript">
        var yourFunction = function () {
          console.log('hCaptcha is ready.');
          var widgetID = hcaptcha.render('captcha-1', { sitekey: 'MY_SITE_KEY' });
        };
      </script>
    </head>
    <body>
        <div class="h-captcha" data-sitekey="MY_SITE_KEY" data-theme="dark"></div>
    </body>
</html>

render隐式调用时,默认的containerIdh-captcha,定义在class目标 div.

当您显式调用 hcaptcha.render() 时,第一个参数是 containerId.

由于这种行为,您的问题可以通过将 render() 调用的第一个参数更改为 h-captcha 而不是 captcha-1 或更改 class 值到 captcha-1.