javascript - 隐藏在 Javascript 中后,按钮未显示
问题描述
我有一堆按钮,有些显示有些隐藏。单击显示的按钮时,它们应该被隐藏,并且应该显示一些隐藏的按钮。不幸的是,只有显示的按钮被隐藏了。隐藏的按钮不会出现。
我已经为按钮尝试了不同的显示类型,但实际上我没有 html、CSS 或 Javascript 来知道我在做什么,或者我在做什么改变了任何东西。
html:
hideGenres();
function proudCondfidentResults() {
hideFeelings();
showIndustrialGothicButton();
showMetalButton();
}
function powerfulPumpedResults() {
hideFeelings();
}
function showIndustrialGothicButton() {
document.getElementById("industrialGothic").style.display = "block";
}
function showMetalButton() {
document.getElementById("metal").style.display = "block";
}
function hideFeelings() {
document.getElementById("feelingButtons").style.display = "none";
}
function hideGenres() {
document.getElementById("genreButtons").style.display = "none";
}
button {
font-family: 'Work Sans', sans-serif;
font-size: 24px;
background-color: #279;
color: #fff;
border: 0;
border-radius: 3px;
cursor: pointer;
margin-right: 0.5%;
margin-bottom: 0.5%;
display: block;
height: 20%;
width: 49%;
float: left;
}
button:hover {
background-color: #38a;
}
<div id="feelingButtons">
<button id="proudConfident" onclick="proudCondfidentResults()">Proud/Confident</button>
<button id="powerfulPumped" onclick="powerfulPumpedResults()">Powerful/Pumped</button>
</div>
<div id="genreButtons">
<button id="industrialGothic" onclick="industrialGothicLink()">Industrial/Gothic</button>
<button id="metal" onclick="metalLink()">Metal</button>
</div>
单击按钮时,Proud/Confident
我希望Proud/Confident
andPowerful/Pumped
按钮消失,而Industrial/Gothic
andMetal
按钮会出现。当前发生的是Proud/Confident
andPowerful/Pumped
按钮消失,但Industrial/Gothic
andMetal
按钮保持隐藏。你如何使它显示Industrial/Gothic
和Metal
按钮?
解决方案
需要更改genreButtons
div的显示样式
hideGenres();
function proudCondfidentResults() {
hideFeelings();
industrialGothicLink();
showMetalButton();
}
function powerfulPumpedResults() {
hideFeelings();
}
function industrialGothicLink() {
document.getElementById("industrialGothic").style.display = "block";
}
function showMetalButton() {
document.getElementById("metal").style.display = "block";
}
function hideFeelings() {
document.getElementById("feelingButtons").style.display = "none";
//changed here
document.getElementById("genreButtons").style.display = "block";
}
function hideGenres() {
document.getElementById("genreButtons").style.display = "none";
}
button {
font-family: 'Work Sans', sans-serif;
font-size: 24px;
background-color: #279;
color: #fff;
border: 0;
border-radius: 3px;
cursor: pointer;
margin-right: 0.5%;
margin-bottom: 0.5%;
display: block;
height: 20%;
width: 49%;
float: left;
}
button:hover {
background-color: #38a;
}
<div id="feelingButtons">
<button id="proudConfident" onclick="proudCondfidentResults()">Proud/Confident</button>
<button id="powerfulPumped" onclick="powerfulPumpedResults()">Powerful/Pumped</button>
</div>
<div id="genreButtons">
<button id="industrialGothic" onclick="industrialGothicLink()">Industrial/Gothic</button>
<button id="metal" onclick="metalLink()">Metal</button>
推荐阅读
- java - 无法使用 Selenium java 库获取 cookie
- javascript - 地图功能错误:无法读取 Reactjs 中未定义的属性“地图”
- c# - c#如何确定是否在不同的键盘设置中按下了键
- c# - 将 reader.GetGuid(0) 与 Postgres 一起使用时出现奇怪的错误
- c++ - glm 旋转和平移
- algorithm - 给定一个由 0-9 组成的数组和一个整数 n,找出所有可以从输入数组组成且小于 n 的整数
- ballerina - Ballerina Composer Try-it 从外部 cURL 或 Chrome 请求 404 但 OK
- html - html 舍入 mask="9?9?9?9?9.99"....大约 1/4 的时间
- r - dplyr 用 R 中的位置替换
- node.js - 如何通过 CORS 传递 cookie?