[英]hide div when page load
我有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,");
});
});
我的.toggle_container总是很好用,但是我想在页面加载时第一次关闭它。 能帮我解决一下吗? 我不想使用$(“。toggle_container”)。hide(); 这个问题的功能,因为当我点击href然后.toggle_container不应该隐藏,它应该打开。
问候。
你可以添加属性
style="display:none"
你的元素.toggle_container。
然后在第一次调用$(document).ready时会显示。
完整的测试示例:
<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>
注意:没有$(“。toggle_container”)。show(); 在$(文件).ready
去除
$(".toggle_container").show();
来自你的$(document).ready
函数。
在html部分中为toggle_container
div
添加style="display:none"
。
查看@HCK的回复。 他明确提到了..
文档加载后,将提示“页面加载”警告框。
$(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.