[英]How can I show / hide a div using the properties from a CSS file using JavaScript
I'm looking to show a div that's initial display value is set to "none" in the HTML file. 我希望显示HTML文件中将div的初始显示值设置为“ none”的值。 I don't want to use $(object).style.display = "initial" because it doesn't format the page right.
我不想使用$(object).style.display =“ initial”,因为它不会正确格式化页面。 I'm sure there is a way to do this.
我敢肯定有办法做到这一点。 Can anybody help?
有人可以帮忙吗?
JavaScript: JavaScript:
function showPrecip() {
$("slider").style.display = "none";
$("graph").style.display = "initial";}
CSS: CSS:
#graph td div {
background-color: #e7f1fd;
border-top: 2px solid #1878f0;
font-weight: bold;
text-align: center;
width: 50px;}
#graph td, #temps {
height: 100px;
vertical-align: bottom;}
HTML: HTML:
<table id="graph">
</table>
<div id="temps">
<input id="slider" type="range" min="0" max="24" step="3" />
</div>
Default Behaviour for div is Block. div的默认行为是“阻止”。
Just change the javascript to the below should be alright. 只需将javascript更改为以下内容就可以了。 As i use this method for this part.
因为我在这一部分使用了这种方法。 $("graph").style.display = "";
$(“ graph”)。style.display =“”;
Make a CSS class 制作一个CSS类
.hidden {
display: none;
}
Toggle it with JS as needed 根据需要使用JS进行切换
function showPrecip() {
$("slider").addClass("hidden");
$("graph").removeClass("hidden");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.