function Myfunction1() {
var a = document.getElementById("signup");
var b = document.getElementById("loginpage1");
if (a.style.display === "none") {
a.style.display = "block";
b.style.display = "none";
} else {
b.style.display = "none";
}
}
答案 0 :(得分:0)
这example会帮助你。
function Myfunction1() {
var a = document.getElementById("signup");
var b = document.getElementById("loginpage1");
if (a.style.display === "none") {
a.style.display = "block";
b.style.display = "none";
} else {
a.style.display = "none";
b.style.display = "block";
}
}
答案 1 :(得分:0)
当您通过CSS选择器特别从外部样式表文件隐藏时,a.style.display === "none"
始终不起作用。要克服这种情况,请尝试以下方式:
function Myfunction1() {
var a = document.getElementById("signup");
var b = document.getElementById("loginpage1");
if (a.offsetParent === null) {
a.style.display = "block";
b.style.display = "none";
} else {
a.style.display = "none";
b.style.display = "block";
}
}