[英]hide div when page load
I have jquery issue, Kindly see my jquery code: 我有jquery问题,请看我的jquery代码:
$(document).ready(function(){
$(".toggle_container").show();
$("h2.trigger").toggle(function(){
$(this).addClass("active");
}, function () {
$(this).removeClass("active");
});
$("h2.trigger").click(function(){
$(this).next(".toggle_container").slideToggle("slow,");
});
});
My .toggle_container is shown always its good, But I want to close it first time, when page load. 我的.toggle_container总是很好用,但是我想在页面加载时第一次关闭它。 Can you please provide me any solution?
能帮我解决一下吗? I dont want to use $(".toggle_container").hide();
我不想使用$(“。toggle_container”)。hide(); function for this problem because when i click on href then .toggle_container should not hide, It should open.
这个问题的功能,因为当我点击href然后.toggle_container不应该隐藏,它应该打开。
Regards. 问候。
You can just add attribute 你可以添加属性
style="display:none"
to your element .toggle_container. 你的元素.toggle_container。
Then on first call of $(document).ready it will be shown. 然后在第一次调用$(document).ready时会显示。
The full test example: 完整的测试示例:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("h2.trigger").click(function(){
$(this).next(".toggle_container").slideToggle("slow,");
});
});
</script>
</head>
<body>
<h2 class="trigger">Toggle</h2>
<div class="toggle_container" style="display:none">Container</div>
</body>
</html>
Note: there`s no $(".toggle_container").show(); 注意:没有$(“。toggle_container”)。show(); on $(document).ready
在$(文件).ready
remove the 去除
$(".toggle_container").show();
from your $(document).ready
function. 来自你的
$(document).ready
函数。
in html part add style="display:none"
for the toggle_container
div
. 在html部分中为
toggle_container
div
添加style="display:none"
。
check the @HCK s reply. 查看@HCK的回复。 he is clearly mentioned it..
他明确提到了..
Once the document gets loaded, a alert box will be prompted "page loaded". 文档加载后,将提示“页面加载”警告框。
$(document).ready(function(){
alert('page loaded'); // alert to confirm the page is loaded
$('.divClassName').hide(); //enter the class or id of the particular html element which you wish to hide.
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.