解决了:
主要问题在于:
<!doctype html>
<html>
<head>
<title>test</title>
<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#main_body').append("<h1>Hello</h1><input id=\"but\" type=\"button\">Click");
$( "#but" ).on( "click", function() {
alert( "bla bla" );
});
});
</script>
</head>
<body id="main_body">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我觉得jquery太老了
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
解决了问题:)
添加DOM后为什么警报不起作用?点击它后应显示"bla bla".
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
Run Code Online (Sandbox Code Playgroud) 可以在一个表单中添加多个reCAPTCHAS吗?我尝试这样做,甚至给多个reCAPTCHAS提供不同的ID,但是当我在浏览器中加载页面时,只显示其中一个.
这是设计的吗?我需要两个reCAPTCHAS,因为一个用于登录,另一个用于Register表单,它将显示在同一页面上.
谢谢!WT
我在一个页面上有两个表单,都使用Google reCAPTCHA.
每当我使用grecaptcha.reset();它时,只会重置第一个实例.
以下JS呈现reCAPTCHA(s)
var recaptcha1;
var recaptcha2;
var myCallBack = function() {
//Render the recaptcha1 on the element with ID "recaptcha1"
recaptcha1 = grecaptcha.render('recaptcha1', {
'sitekey' : '1234', //Replace this with your Site key
'theme' : 'light'
});
//Render the recaptcha2 on the element with ID "recaptcha2"
recaptcha2 = grecaptcha.render('recaptcha2', {
'sitekey' : '1234', //Replace this with your Site key
'theme' : 'light'
});
};
Run Code Online (Sandbox Code Playgroud)
如何重置所有实例或定位特定实例.
我已经在单页中实现了两个recaptcha,但只有一个是recaptcha正在工作
我的代码是针对验证码1的
<div class="resumator-label resumator-resume-text" id="resumator-recaptcha_forward-label">Human Check*</div>
<div class="resumator-input" id="resumator-recaptcha_forward-field">
<div id="div_error_resumator-forward-recaptcha-value" class="dv_error"><span>Please enter the text:</span></div><script type="text/javascript" src="//www.google.com/recaptcha/api/challenge?k=6Ld99tsSAAAAAIy-Zv3YKxCOefk2IXELOBVNhM7Y"></script>
<noscript>
<iframe src="//www.google.com/recaptcha/api/noscript?k=6Ld99tsSAAAAAIy-Zv3YKxCOefk2IXELOBVNhM7Y" 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>
Run Code Online (Sandbox Code Playgroud)
其他其他验证码的代码
<div class="resumator-field-wrapper resumator-resume-text" id="resumator-recaptcha">
<div class="resumator-label resumator-resume-text" id="resumator-recaptcha-label">Human Check*</div>
<div class="resumator-input" id="resumator-recaptcha-field">
<script type="text/javascript" src="//www.google.com/recaptcha/api/challenge?k=6Ld99tsSAAAAAIy-Zv3YKxCOefk2IXELOBVNhM7Y"></script>
<noscript>
<iframe src="//www.google.com/recaptcha/api/noscript?k=6Ld99tsSAAAAAIy-Zv3YKxCOefk2IXELOBVNhM7Y" 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>
</div>
Run Code Online (Sandbox Code Playgroud)
我也使用克隆工作正常
//复制我们的reCapcha
$('#resumator-recaptcha-label').html($('#resumator-recaptcha_forward').clone(true,true));
Run Code Online (Sandbox Code Playgroud)
克隆验证码中的问题,其重新加载验证码和其他链接不适用于新的克隆验证码
我正在尝试使用Google Invisible reCAPTCHA,但是g-recaptcha-response当我在同一页面中有多个表单时,它将发送POST参数为空。这是我的代码:
谷歌JS
<script src="//google.com/recaptcha/api.js?hl=pt-BR&onload=captchaCallback&render=explicit" async defer></script>
Run Code Online (Sandbox Code Playgroud)
表格1
<form action="/site/Contact/send" id="form1">
<input type="text" name="nome" required>
<div class="g-recaptcha"
data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxx"
data-callback="form1Callback"
data-size="invisible">
</div>
<button type="submit">Send</button>
</form>
Run Code Online (Sandbox Code Playgroud)
表格2
<form action="/site/Contact/send" id="form2">
<input type="text" name="nome" required>
<div class="g-recaptcha"
data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxx"
data-callback="form2Callback"
data-size="invisible">
</div>
<button type="submit">Send</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我的JS(基于此答案)
$(document).ready(function() {
window.captchaCallback = function(){
$('.g-recaptcha').each(function(index, el) {
var attributes = {
'sitekey' : $(el).data('sitekey'),
'size' : $(el).data('size'),
'callback' : $(el).data('callback')
};
grecaptcha.render(el, attributes);
});
};
window.form1Callback = function(){
$('#form1').submit(); …Run Code Online (Sandbox Code Playgroud)