我使用下面的脚本来创建打开和关闭div的切换效果。
<script type="text/javascript" src="/mainmenu/js/jquery.min.4.1.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery(".content").hide();
jQuery(".heading").click(function()
{
jQuery(".content").hide();
jQuery(this).next(".content").slideToggle(500);
});
});
</script>
<div class="main_text_faq"
<p class="heading">Header-1 </p>
<div class="content">Lorem ipsum</div>
<p class="heading">Header-2</p>
<div class="content">Lorem ipsum</div>
<p class="heading">Header-3</p>
<div class="content">Lorem ipsum</div>
</div>现在,我似乎不能简单地弄清楚如何让标题1始终处于打开状态,并在输入内容时将标题2打开。你知道我该怎么开始编码吗?我正在学习如何使用Jquery,所以请原谅我没有任何东西可以展示,因为我已经尝试解决了我的“问题”。
提前谢谢。致以问候!
发布于 2011-09-05 20:58:13
如果我没理解错的话,您希望第一个.content元素在其他元素最初被隐藏时保持可见。为此,您可以使用:not和:first伪选择器来排除第一个元素:
jQuery(".content:not(:first)").hide();这是一个working example。
https://stackoverflow.com/questions/7308375
复制相似问题