JavaScript 密码验证 onkeydown 不工作

JavaScript Password Verification onkeydown not working

我尝试实现了简单的密码验证,但以下功能似乎不起作用,它们甚至没有显示在控制台中。有没有我遗漏的非常简单的东西?

"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>

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