为了账号安全,请及时绑定邮箱和手机立即绑定

JavaScript 密码验证 onkeydown 不起作用

JavaScript 密码验证 onkeydown 不起作用

料青山看我应如是 2023-11-11 21:16:57
我尝试实现简单的密码验证,但以下功能似乎不起作用,它们甚至没有显示在控制台中。我是否缺少一些非常简单的东西?"user strict";window.onload = init;function init() {    document.getElementById("newPassword").onkeydown = checkPassword;    document.getElementById("confirmPassword").onkeydown = checkConfirm;}function checkPassword(event){    let newPass = document.getElementById("newPassword").value;    var passwordRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*&])[A-Za-z\d]@$!%*?&]{8,}$")    if(!passwordRegex.test(newPass)){        feedback.innerHTML = "'"+newPass + "' is not secure."        let result = passwordRegex.test(newpass);        console.log("result: " + result);        return false;    }    return true;}function checkConfirm(event) {    let confirmPass = document.getElementById("confirmPassword").value;    let newPass = document.getElement("newPassword").value;    if(newPass != confirmPassword)) {        feedback.innerHTML = "Password does not match.";            return false;    }    return true;}let feedback - document.getElementById("feedback");function newUserRequest() {}function checkUser() {    let email = document.getElementById(emailUser).value;    let password = document.getElementById("passwordUser").value;}<div class="itemsFormDisplay">    <label class="detailNames">Password</label><br>    <input id="newPassword" class="detailsFields" type="password" name="password" required></div><div class="itemsFormDisplay">    <label class="detailNames">ConfirmPassword</label><br>    <input id="confirmPassword" class="detailsFields" type="password" name="password" required></div>
查看完整描述

1 回答

?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

更改window.onload = init;window.onload = init();



查看完整回答
反对 回复 2023-11-11
  • 1 回答
  • 0 关注
  • 119 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信