typescript 从HtmlInputElement中获取值并使用用户传递进行检查

v2g6jxz6  于 2023-03-13  发布在  TypeScript
关注(0)|答案(1)|浏览(118)

我想获取此值并检查现有用户密码:

const Users =[{
  userName: 'Hasan1934',
      password: 'Qwx32dksa'
}]

和输入值:const UserName = document.getElementById("username-field")const Password = document.getElementById("password-field")和条件:

for (let index = 0; index < Users.length; index++) {
            let ArrayItem = Users[index];
            if (UserName === ArrayItem.userName && Password === arrayItem.password ) {
                // console.log("your in !!!!!!!!!!!**********");
                break;}}

它对我来说不起作用const UserNameHtml = (document.getElementById("username-field") as HTMLInputElement).value

2g32fytz

2g32fytz1#

试试这个

const Users =[{
   userName: 'Hasan1934',
   password: 'Qwx32dksa'
}]

function isUserExist() {
   const UserName = document.getElementById("username-field");
   const Password = document.getElementById("password-field");
   return !!Users.find(u=>u.userName===UserName.value &&u.password===Password.value);
}
isUserExist();

相关问题