Checkbox “;就条款达成一致”-复选框更改错误消息

Checkbox “;就条款达成一致”-复选框更改错误消息,checkbox,Checkbox,我使用这个问题代码在我的PHP Wordpress页面上添加“同意条款”,但如果用户不接受复选框,我需要更改错误消息 有可能吗 这是我的代码使用 <form action="#" onsubmit="if(document.getElementById('agree').checked) { return true; } else { alert('Please indicate that you have read and agree to the Terms and Condition

我使用这个问题代码在我的PHP Wordpress页面上添加“同意条款”,但如果用户不接受复选框,我需要更改错误消息

有可能吗

这是我的代码使用

<form action="#" onsubmit="if(document.getElementById('agree').checked) { return true; } else { alert('Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'); return false; }">
    <input type="checkbox" required name="checkbox" value="check" id="agree" /> I have read and agree to the Terms and Conditions and Privacy Policy
    <button type="submit" class="btn" name="reg_user">Register</button>
</form>

我已阅读并同意条款和条件以及隐私政策
登记

只需在代码中更改此字符串:

'Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'
确保不要在错误消息本身中使用
——它定义字符串的结尾

编辑:

如果删除
required name=“checkbox”
它应该可以工作
因为如果您的代码中确实有所需的名称,那么表单本身将检查复选框是否被选中。这将导致js代码无法执行。另外,你应该考虑把你的JS代码分成一个单独的文件。

问题是,如果我不点击复选框,而是出现经典的“FLID是请求”,“请注明“世界等”不会出现。我如何解决这个问题?如果它对你有效,请投票给我正确的答案