Javascript SweetAlert模式窗口中的Google reCaptcha

Javascript SweetAlert模式窗口中的Google reCaptcha,javascript,jquery,recaptcha,sweetalert,Javascript,Jquery,Recaptcha,Sweetalert,我正在处理一个函数,该函数需要在SweetAlert弹出框中执行reCaptcha验证,但我得到以下错误: 未捕获错误:reCAPTCHA占位符元素必须是元素或id 我一直在研究是什么导致了这个错误,我注意到这是因为元素在试图生成reCaptcha元素时还没有被加载 函数confirbox(){ var div=document.createElement('div'); div.id='recaptcha'; div.onload=genRecaptcha(); 游泳({ 标题:“你确定吗?

我正在处理一个函数,该函数需要在SweetAlert弹出框中执行reCaptcha验证,但我得到以下错误:

未捕获错误:reCAPTCHA占位符元素必须是元素或id

我一直在研究是什么导致了这个错误,我注意到这是因为元素在试图生成reCaptcha元素时还没有被加载

函数confirbox(){
var div=document.createElement('div');
div.id='recaptcha';
div.onload=genRecaptcha();
游泳({
标题:“你确定吗?”,
目录:div,
图标:“警告”,
按钮:是的,
丹格莫德:没错,
})
}
函数genRecaptcha(){
console.log($('recaptcha').attr('id');
grecaptcha.render('recaptcha'{
“站点密钥”:“6le2zfuuaaaaaaev4im\u 5weEnXg4gVplan2Atgiaj”
});
}
$('#btn1')。单击(确认框)


提交
使用
$(元素)解决问题。准备好
从而不是使用
。onload

下面提供的代码片段无法正常运行,因为recaptcha站点密钥对此站点无效

函数confirbox(){
var div=document.createElement('div');
div.id='recaptcha';
$('#recaptcha').ready(函数(){
console.log($('recaptcha').attr('id');
grecaptcha.render('recaptcha'{
“站点密钥”:“6le2zfuuaaaaaaev4im\u 5weEnXg4gVplan2Atgiaj”
});
})
游泳({
标题:“你确定吗?”,
目录:div,
图标:“警告”,
按钮:是的,
丹格莫德:没错,
})
}
$('#btn1')。单击(确认框)


提交
UPD:以下是现场演示:


以下是使用支持的SweetAlert分支的解决方案:

函数showWeetAlertReCAPTCHA(){
喷火({
标题:“SweetAlert2+Recaptcha”,
html:“”,
onOpen:function(){
grecaptcha.render('recaptcha'{
“站点密钥”:“6LDVPLUUAAAAK_Y5M_wR7s-UWUISEDV8K-tCq”
});
}, 
预确认:功能(){
if(grecaptcha.getResponse().length==0){
Swal.showValidationMessage(`请确认您不是机器人')
}
}
})
}
#recaptcha>div{
宽度:自动!重要;
边缘底部:.5em;
}


@ZubairNazerOliyat对此表示赞赏,但对问题的解决将不胜感激对于当前版本8.2.5,您应该使用
swal.showValidationMessage('请验证您不是机器人')