javascript 在页面加载时隐藏具有特定类的 div,然后在加载后再次显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19945002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide div with specific class while page is loading then show again after load
提问by markyeoj
I want to hide an specific div class while page is loading. The structure is..
我想在页面加载时隐藏特定的 div 类。结构是..
<div id ="container">
<div class="project-item tv"></div>
<div class="project-item radio"></div>
<div class="project-item radio"></div>
<div class="project-item tv"></div>
</div>
For example, I want to hide DIV with class radio while page is loading, then show them again after load. Thanks.
例如,我想在页面加载时隐藏带有 class radio 的 DIV,然后在加载后再次显示它们。谢谢。
回答by user2415992
First, set it's CSS value to display:none
首先,将它的 CSS 值设置为 display:none
Then, in a Javascript file, the jQuery solution would be to use:
然后,在 Javascript 文件中,jQuery 解决方案将使用:
$(document).ready(function() {
$("#yourdivid").show();
});
$(document).ready()
makes sure that the entire DOM is loaded before the code inside the function is executed
$(document).ready()
确保在执行函数内的代码之前加载整个 DOM
回答by Tushar Gupta - curioustushar
Use CSS
使用 CSS
hide div using css
使用css隐藏div
div.radio {
display:none;
}
js
js
Show div with class radio on DOM ready
在DOM上显示带有 class radio 的 div
$(document).ready(function () {
$('div.radio').show();
});
在加载时显示带有类收音机的 div
$(window).load(function () {
$('div.radio').show();
});
Read What is the difference between $(window).load and $(document).ready?
回答by Nuwan Dammika
<style>
div .radio {display:none;}
</style>
<div id ="container">
<div class="project-item tv"></div>
<div class="project-item radio"></div>
<div class="project-item radio"></div>
<div class="project-item tv"></div>
</div>
in JS
在JS中
$().ready(function() {$("div .radio").css("display":"block")});
回答by Harvinder Kheng
CSS:
CSS:
.hidden { display: none; }
HTML:
HTML:
<div id="blah" class="hidden"><!-- content --></div>
JQUERY:
查询:
$(function () {
$('#blah').removeClass('hidden');
});