javascript - 未更新使用 JavaScript 的密码确认
问题描述
我有一个注册表。它成功检查了密码输入和确认密码输入的值。(如果两个密码匹配,X 变为✔️) 问题是,出现复选标记后,它看起来就像卡在那里!当我更改密码时,复选标记应更改为 X,但事实并非如此!它卡在✔️!
<div id="confirm_pass2">
<span id="password_confirmation" class="unconfirmed_pass"></span>
</div>
<script>
var confirmation = document.getElementById("confirm_password");
confirmation.onfocus = function (){
document.getElementById("confirm_pass2").style.display = "block";
}
confirmation.onblur = function (){
document.getElementById("confirm_pass2").style.display = "none";
}
confirmation.onkeyup = function () {
if (document.getElementById("confirm_password").value.match(document.getElementById("password").value)){
document.getElementById("password_confirmation").classList.remove("unconfirmed_pass");
document.getElementById("password_confirmation").classList.add("confirmed_pass");
} }
</script>
<style>
#confirm_pass2 {
position: absolute;
display: none;
}
.confirmed_pass:before {
position: absolute;
font-size: 25px;
right: 642px;
bottom: 197px;
font-weight: bold;
color: green;
content: "✔";
}
.unconfirmed_pass:before {
font-family: calibri;
position: absolute;
right: 647px;
bottom: 205px;
font-size: 22px;
font-weight: bold;
color: red;
content: "X";
}
</style>
更新 我将“匹配”更改为 ==,一切似乎都运行良好。
if (document.getElementById("confirm_password").value == document.getElementById("password_new").value){...
解决方案
您如何尝试在其中添加其他条件,例如
confirmation.onkeyup = function () {
if (document.getElementById("confirm_password").value.match(document.getElementById("password_new").value)){
document.getElementById("password_confirmation").classList.remove("unconfirmed_pass"); document.getElementById("password_confirmation").classList.add("confirmed_pass");
} else {
document.getElementById("password_confirmation").classList.remove("confirmed_pass"); document.getElementById("password_confirmation").classList.add("unconfirmed_pass");
}
}
推荐阅读
- python - 如何摆脱python中的大块空白?
- json - jsonschema2pojo 生成对象类型的所有变量,但不是我提供的数据类型
- elasticsearch - 为什么 searchResult.TotalHits() 与 len(searchResult.Hits.Hits) 不同?
- java - 从不同的片段访问列表
- pandas - 如何在熊猫列上计算非空值然后聚合
- c# - TFS (AzureDevOps) 2015 C# 获取构建中使用的变量
- node.js - 将 S3 存储桶的内容复制到另一个存储桶 | 节点JS
- angular - 如何在点击时打开弹出窗口?
- c# - 我想在数据表中添加新行而不对现有数据产生任何影响
- string - 如果列表中包含特定单词,如何从列表中删除字符串