我希望使用google的recaptcha添加到我的网站。如果recaptcha将true返回到发送按钮,则html表单只需调用MAILTO
操作。这是<head>
和<body>
。
<head>
<script type="text/javascript">
var onloadCallback = function() {
grecaptcha.render('html_element', {
'sitekey' : 'my key'
});
};
</script>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form action="MAILTO:my.email@example.com" method="post" enctype="text/plain">
Name<br><input type="text"><br><br>
E-mail<br><input type="text"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
<div class="g-recaptcha" data-sitekey="mykey"></div>
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer>
</script>
</body>
一个问题是我是javascript的新手,所以正确地遵循google's javascript API一直很困难。可以随时按下send
按钮。
简而言之,我想学的是:
答案 0 :(得分:0)
<script type="text/javascript">
var verifyCallback = function(response) {
//called when success
document.all.body.hide.style.display="block";
};
var onloadCallback = function(){
grecaptcha.render('verify', {
'sitekey' : 'your_site_key',
'callback' : verifyCallback,
'theme' : 'dark'
});
};
</script>
</head>
<body>
<div id="verify"></div>
<form>
<button type="submit" id="hide">Submit</button>
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer>
</script>
<style>#hide{display:none;}</style> </body></html>