当我按下按钮并显示一个元素时,我想这样做,然后按另一个并显示另一个元素,但它不起作用。我目前的代码是:
function login() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == "Ethan" && password == "Horton") {
document.getElementById("test").innerHTML = "Logged In: Ethan";
document.getElementById("p1").style.visibility = "hidden";
document.getElementById("Logout").style.visibility = "visible";
} else if (username == "Person" && password == "Password") {
document.getElementById("test").innerHTML = "Logged In: Person";
document.getElementById("p1").style.visibility = "hidden";
document.getElementById("p1").style.visibility = "hidden";
document.getElementById("Logout").style.visibility = "visible";
} else {
alert("Incorrect User/Pass");
}
}
正如你所看到的,我需要改变很多东西,但它不会这样做。帮助
答案 0 :(得分:0)
快速&简易解决方案
确保在HTML中使用双引号内的单引号。
onclick="document.getElementById('p1').style.visibility='visible'"
正确的解决方案