[英]I've made something hidden in css, i can't make it visible now when I click a button
I'm pretty new to all of this and still learning :s 我对所有这些都很新,仍然在学习:s
So in my css, i've done this... 所以在我的CSS中,我已经做到了...
.example {
display: none;
}
I have a button which when i click makes other divs invis as well as trying to make it so that .example will be visible. 我有一个按钮,当我单击该按钮时,会使其他div变得不可见,并试图使其显示为.example。
I am using an onClick function...this is where I set the other div invis... 我正在使用onClick函数...这是我设置其他div的地方...
document.getElementById("thisdiv").style.display = "none";
I can't seem to figure out how to make the other div visible now? 我似乎无法弄清楚如何使另一个div现在可见?
将显示设置为“阻止”或使用jQuery的show()函数
$('.example').show();
document.getElementById("thisdiv").style.display = "block";
Refer this: 引用此:
$("#show").click(function(){
$(".example").css({"display":"block"});
});
$("#hide").click(function(){
$(".example").css({"display":"none"});
});
Fiddle: http://jsfiddle.net/981oek8z/ 小提琴: http : //jsfiddle.net/981oek8z/
Since you haven't posted much of your source code I have created a little demo to show you how to set the display for all elements using a class. 由于您没有发布太多的源代码,因此我创建了一个小样的演示来向您展示如何使用类为所有元素设置显示。
This doesn't require jQuery 这不需要jQuery
function showclass(){ document.getElementById('thisdiv').style.display="none"; var examples=document.getElementsByClassName('example'); for(var i=0; i<examples.length; i++){ examples[i].style.display="block"; } }
.example{display:none;}
<button onclick="showclass()">Show example Class</button> <div id="thisdiv"> This Div will disappear </div> <div class="example">Example Div One</div> <div class="example">Example Div Two</div> <div class="example">Example Div Three</div>
I hope this helps, happy coding! 希望对您有所帮助,编码愉快! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.