提示中的条件语句

conditional statment in prompt

我正在努力根据权利 username/password 为用户提供两张不同的图片。我有一个提示弹出窗口,让用户提供 username/password,在提供正确的凭据后,登录图片应该出现,如果凭据错误,注销图片应该出现。我正在使用 getElementById 进行相应更改。此时出现提示,但没有显示图片

<img src="user_in.PNG" id="user_in_id" hidden>
<img src="user_out.PNG" id="user_out_id" hidden>

<script> 
      
     var person = prompt("Please enter your name", ""); 
     var password = prompt("Please enter your password", "");
     if (person == "admin" && password =="admin") {
        alert("Welcome, You are now Logged in");
        document.getElementById("user_in_id");

      }else
        alert("wrong username or password");
        document.getElementById("user_out_id");
      
</script>

您必须对 document.getElementById("user_in_id") 选择器应用一个函数,以某种方式使所选元素可见。

一种方法是使用 document.getElementById("user_in_id").removeAttribute("hidden");

从其中删除 hidden 属性

您还忘记了将 else 语句括在花括号中以便正常工作。

<img src="https://styles.redditmedia.com/t5_3obin/styles/communityIcon_5v6pv5kqz5241.PNG" id="user_in_id" hidden>
<img src="https://public.blenderkit.com/thumbnails/assets/0992088bfb844c69bb6e426272970c8b/files/thumbnail_c858218a-4afc-4e94-b6b9-080f5e6c7066.jpg.256x256_q85_crop-%2C.jpg" id="user_out_id" hidden>

<script>
    var person = prompt("Please enter your name", ""); 
    var password = prompt("Please enter your password", "");
     if (person === "admin" && password === "admin") {
        alert("Welcome, You are now Logged in");
        document.getElementById("user_in_id").removeAttribute("hidden");

      }else{ 
       alert("wrong username or password");
       document.getElementById("user_out_id").removeAttribute("hidden");
      }
        
      
</script>