【发布时间】:2019-01-07 20:51:32
【问题描述】:
我有 2 个 50% 宽度的开关,点击它会显示 100% 以下的 div 并隐藏另一个,反之亦然。
使这成为可能的功能工作正常,但我想做的是在显示的切换上添加自定义样式
`
function switch_div(show) {
document.getElementById("show_"+show).style.display="block";
document.getElementById("show_"+((show==1)?2:1)).style.display = "none";
}
function stylish(){
document.getElementById("borderRight").setAttribute(
"style", "color:#000000;border:1px solid black;border-bottom:5px solid black;");
document.getElementById("buttonRight").style.color = "#000000";
}
function stylish2(){
document.getElementById("borderLeft").setAttribute(
"style", "color:#000000;border:1px solid black;border-bottom:5px solid black;");
document.getElementById("buttonLeft").style.color = "#000000";
}
.content {
width: 100%;
height: 100px;
display: block;
background-color:#fafafa;
margin-top:3%;
}
.hide {
display: none;
}
.align1{
display:inline-block;
width:49%;
height:50px;
text-align:center;
border:1px solid #c3c6c6;
cursor:pointer;
}
#borderRight{
border-right:0px;
}
.titres{
font-family:Roboto;
font-size:20px;
background-color:transparent;
border:0px;
padding-top:2.3%;
font-weight:700;
color:#a2a2a4;
text-transform:uppercase;
font-size:20px;
letter-spacing:1.5px;
cursor:pointer;
}
.titres:hover{
color:#000000;
}
<div id="borderRight" class="align1" onclick="switch_div(1);">
<button id="buttonRight" class="titres" onclick="stylish()">Description</button>
</div><div id="borderLeft"class="align1"onclick="switch_div(2);"><button id="buttonLeft" class="titres" onclick="stylish2()">
Additional information</button>
</div>
<div class="content" id="show_1">
Show by default (and when button 1 is clicked)
</div>
<div class="content hide" id="show_2">
Div number 2
</div>
`
感谢您的帮助!
【问题讨论】:
-
阿联酋在 css 上的 active 或 fucus 方法很容易
-
@Dario 添加了anwser,请查看
标签: javascript html css