输入错误密码时显示消息
display message on wrong password entry
我有一个提交按钮,只有在"胜利"输入表单时才有效。现在我正试图工作在一个错误消息显示"错误的关键字条目",如果输入到表单字段的文本不是"胜利"。下面是代码
<form name="input" action="index.html" method="post" onsubmit="return check();">
<input type="text" maxlength="7" autocomplete="off" name="" id="victory">
<br><input type="submit" class="bigbutton" value="NEXT">
</form>
<script>
function check(){
if(document.getElementById("victory").value == "victory")
return true;
else
return false;
}
如果我是你,我会添加一个HTML元素来填充错误。然后你可以用你喜欢的CSS样式。
<div id="error"></div>
那么你的函数看起来就像这样:
function check(){
if(document.getElementById("victory").value == "victory")
return true;
else
document.getElementById("error").innerHTML = "Wrong keyword entry."
return false;
}
您可以简单地在else
条件中添加警报…
function check(){
if(document.getElementById("victory").value == "victory") {
return true;
}
else {
alert("wrong keyword entry");
return false;
}
}
相关文章:
- 如果下载不成功,如何显示消息
- 如何在 jquery 中的速率按钮下方显示消息状态
- 删除所有可拖动元素后如何显示消息
- php表单验证n在表单上显示消息3秒钟并淡出
- 单击“点赞”按钮时显示消息
- javascript初学者-无法在屏幕上显示消息框
- 在表单提交后显示消息的方法
- 遍历列表,并在jQuery为空时显示消息
- 在jquery幻灯片登录表单上显示消息
- 如果文本筛选器在ng重复中未返回结果,则显示消息
- 以javascript显示消息框
- 在angular 1中,我如何检测angular是否受支持,并在屏幕上显示消息's不受支持
- 浏览器全屏显示,按键时不显示消息
- 选取随机数组元素,将其移除,并在没有更多可用元素时显示消息
- 仅当浏览器不是Google Chrome时显示消息
- 如果所有李都被隐藏,则显示消息
- 在提交表单和显示消息之前,如何检查表单输入是否全是数字
- 如果使用 JavaScript 登录失败,如何在登录页面中显示消息
- j查询验证未显示消息
- 为什么不显示消息