根据正确的用户名/密码,我正在为用户提供两张不同的图片。我有一个提示弹出供用户提供用户名/密码,在提供正确的凭据之后,登录图片应该会出现,如果凭据是错误的,则应该显示注销图片。我正在使用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>发布于 2022-02-08 18:04:50
您必须向您的document.getElementById("user_in_id")选择器应用一个函数,它以某种方式使所选元素可见。
一种方法是使用hidden从其中删除document.getElementById("user_in_id").removeAttribute("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>
https://stackoverflow.com/questions/71038193
复制相似问题