【发布时间】:2020-09-02 17:26:54
【问题描述】:
我正在尝试让我们的联系页面仅在输入正确的短语后才允许提交。 我不知道如何并尝试了警报功能。它会在输入错误的短语时发出警报,但仍会提交表单。基本上我试图阻止自动提交我们的表单。
相关代码:
**HTML:**
<label for="phrase" class="p">Please enter "security" below</label><br>
<input type="text" id="phrase" name="phrase" required></type><br>
<input type="submit"; onclick="no_spam()"; value="Submit"></type>
**JS:**
function no_spam() {
var spam = document.getElementById("phrase").value;
if(spam !== "security")
{alert("Enter correct phrase")}
}
【问题讨论】:
-
你要熟悉forms
-
我建议您看看 google recaptcha 并尝试使用它。无需重新发明轮子。
-
谢谢。模式属性完美运行。重新回顾:我不是想重新发明轮子,只是好奇如何让它发挥作用。现在我知道。谢谢。
标签: javascript