gpt4 book ai didi

javascript - 如果另一个 if 语句为真,如何停止 if 语句

转载 作者:行者123 更新时间:2023-11-28 06:09:27 24 4
gpt4 key购买 nike

简单介绍一下如何更改此代码,以便当其中一个 if 语句变为 true 时,它​​会跳过其余语句?

    if (Guitar > Percussion && Guitar > Brass && Guitar > Keyboard && Guitar > Woodwind) // Here I'm checking to see if Guitar is greater than the others
{
var guitarpage = document.getElementById("GuitarPage"); // If guitar is then get the Element ID "GuitarPage"
guitarpage.style.display ="block"; // Then Display that page
}

if (Percussion > Guitar && Percussion > Brass && Percussion > Keyboard && Percussion > Woodwind)
{
var percussionpage = document.getElementById("PercussionPage");
percussionpage.style.display ="block";

}

if (Brass > Guitar && Brass > Brass && Percussion > Keyboard && Brass > Woodwind) {
var brasspage = document.getElementById("BrassPage");
brasspage.style.display ="block";
}

if (Keyboard > Guitar && Keyboard > Keyboard && Percussion > Brass && Keyboard > Woodwind) {
var keyboardpage = document.getElementById("KeyboardPage");
keyboardpage.style.display ="block";
}

if (Woodwind > Guitar && Woodwind > Brass && Woodwind > Keyboard && Woodwind > Percussion) {
var woodpage = document.getElementById("WoodwindPage");
woodpage.style.display ="block";
}

else {
var nonepage = document.getElementById ("NoPage");
nonepage.style.display ="block";

}

再次感谢您的帮助

最佳答案

if (Guitar > Percussion && Guitar > Brass && Guitar > Keyboard && Guitar > Woodwind) // Here I'm checking to see if Guitar is greater than the others
{
var guitarpage = document.getElementById("GuitarPage"); // If guitar is then get the Element ID "GuitarPage"
guitarpage.style.display ="block"; // Then Display that page
}

else if (Percussion > Guitar && Percussion > Brass && Percussion > Keyboard && Percussion > Woodwind)
{
var percussionpage = document.getElementById("PercussionPage");
percussionpage.style.display ="block";

}

else if (Brass > Guitar && Brass > Brass && Percussion > Keyboard && Brass > Woodwind) {
var brasspage = document.getElementById("BrassPage");
brasspage.style.display ="block";
}

else if (Keyboard > Guitar && Keyboard > Keyboard && Percussion > Brass && Keyboard > Woodwind) {
var keyboardpage = document.getElementById("KeyboardPage");
keyboardpage.style.display ="block";
}

else if (Woodwind > Guitar && Woodwind > Brass && Woodwind > Keyboard && Woodwind > Percussion) {
var woodpage = document.getElementById("WoodwindPage");
woodpage.style.display ="block";
}

else {
var nonepage = document.getElementById ("NoPage");
nonepage.style.display ="block";

}

关于javascript - 如果另一个 if 语句为真,如何停止 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com