在下面的脚本中,表单使用required
复选框的属性,但可以在不选中该框的情况下发送它。根据w3cschool,当前所有浏览器都支持此属性。为什么它不起作用?
<html>
<body>
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
<script>
function onTosSubmit(token) {
document.getElementById("tos").submit();
}
</script>
<noscript><?php echo 'enable JS'; ?></noscript>
<form id='tos' action="" method="POST">
<input type="checkbox" name="toscheckbox" id="toscheckbox" required/>
<label for="toscheckbox">I agree with terms of use</label>
<button
class="g-recaptcha"
data-sitekey="My Google reCaptcha API key"
data-callback="onTosSubmit">
Button text
</button>
</form>
</body>
</html>
删除按钮属性允许正确操作,但它们是 recaptcha 所必需的。