本文介绍了默认情况下,使slideToggle()元素在jQuery中折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组要使用jQuery的slideToggle()
方法制作collapsible/expandable
的div.如何默认使所有这些div折叠?我想避免在页面渲染期间/之后在每个元素上显式调用slideToggle()
.
I have a set of divs that I want to make collapsible/expandable
using jQuery's slideToggle()
method. How do I make all of these divs collapsed by default? I'd like to avoid explicitly calling slideToggle()
on each element during/after page rendering.
推荐答案
您将不得不为这些图层分配样式:display:none,以便在进行javascript渲染之前不会显示它们.然后,您可以毫无问题地调用slideToggle().示例:
You will have to assign a style: display:none to these layers, so that they are not displayed before javascript rendering. Then you can call slideToggle() without problems. Example:
<style type="text/css">
.text{display:none}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('span.more').click(function() {
$('p:eq(0)').slideToggle();
$(this).hide();
});
});
</script>
<body>
<p class="text">
I am using jquery <br/>
I am using jquery <br/>
I am using jquery <br/>
I am using jquery <br/>
I am using jquery <br/>
I am using jquery <br/>
</p>
<span class="more">show</span>
这篇关于默认情况下,使slideToggle()元素在jQuery中折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!