简体   繁体   English

我已经在CSS中隐藏了一些内容,但是当我单击按钮时我现在无法使其可见

[英]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.

相关问题 隐藏div后如何显示它? - How can I make a div visible after I've hidden it? 如何使HTML元素被JavaScript隐藏,并在单击按钮时显示? - How can I make HTML elements be hidden by JavaScript, and show up when I click a button? 我使图像看起来像一个可单击的按钮,但是现在当我单击它时,它是否不充当超链接? - I made a image look like a clickable button, but now when I click on it, does not act as hyperlink? 当我点击我的图表时,我怎样才能做点什么? - How can I make something when I click my chart? 当我点击按钮时隐藏的内容没有显示,为什么会这样? - When I click on the button the hidden content doesn't show, why is this? 当按钮在 Gmail 中可见时,如何单击它? - How can I click on a button when it becomes visible in Gmail? 单击“提交”按钮时,如何才能使某些事情不发生 - How can I make something not happen when a “submit” button is clicked 无法提交表单操作,因为它被覆盖隐藏了 - 我试过 Z-Index 和 Pointer-events:none; CSS/反应 - Can't submit Form action since it is hidden by overlay - I've tried Z-Index and Pointer-events:none; CSS/React 如何使用javascript更改按钮的visible / hidden属性? - How can I change the visible / hidden property of a button with javascript? 当我多次单击“提交”按钮(正在加载以发布帖子时)时,该帖子被多次发布 - when I click submit button multiple times(when it's loading to make a post), the post is made multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM