В моей приключенческой игре есть два варианта: 1. Поднимите палку или 2. Оставьте ее там. Вы можете выбрать только один, так что мне интересно, как вы можете скрыть обе кнопки после щелчка. Это текущий код:Как скрыть две кнопки при нажатии одной кнопки?
<script>
function one()
{
var newButton1 = '<button onclick="two()">Pick up stick</button>'; var newButton2 = '<button onclick="three()">Leave it there</button>';
document.getElementById("a").innerHTML="You feel something on the ground, and you think it's a stick."+newButton1+newButton2;
}
function two()
{
document.getElementById("b").innerHTML="You pick up the stick. It might be useful for something.";
}
function three()
{
document.getElementById("c").innerHTML="You leave the stick on the ground and continue on.";
}
</script>
<div style="margin-left:15px; width:200px; margin-top:100px;">
<button onclick="one()">Feel around the cave</button>
</div>
<div style="margin-left:255px; width:200px; margin-top:-15px;">
</div>
<div id="entire" style="margin-left:490px; margin-top:-22px; width:400px; height:600px;"><div id="c"></div><div id="b"></div><div id="a"></div></div>
У вас проблема с большей масштабируемостью. Вам нужна общая функция, которая делает это для вас, передавая параметры, вместо того, чтобы повторять практически один и тот же код для каждого решения. –