JQuery 显示隐藏显示多个内容
我在为多个文档制作 1 个批量展示时遇到问题。该 showhide 还必须能够在其中包含其他元素,例如 ol ul li 等。目前,我无法显示除标签之外的其他内容以及在其中添加另一个 showhide原始 show hide
还可以显示一个包含内容的框。
HTML:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="showhideJQuery.js"></script>
</head>
<style>
.showhide {
width:500px;
height:200px;
margin:1em .5em;
}
.showhide h3 {
margin: 0;
padding: .25em;
background:#0033CC;
border-top:1px solid #666666;
border-bottom:1px solid #666666;
}
.showhide div {
padding: .5em .25em;
}
</style>
<body>
<div class="showhide">
<h3>Title 1</h3>
<div>
<ol>
<li>Hey!</li>
<div class="showhide">
<h3>Another one?!</h3>
<div>YES!</div>
</div>
</ol>
</div>
</div>
</body>
</html>
JQuery
$(document).ready(function(){
$('div.showhide:eq(0)> div').hide();
$('div.showhide:eq(0)> h3').click(function() {
$(this).next().slideToggle('fast');
});
});
Im having trouble making 1 mass showhide for multiple documents. This showhide must be able to contain other elements within it as well, such as ol ul li etc. Currently I'm having trouble showing the other content besides the tag as well as adding another showhide inside of the original show hide
Also to display a box with the content in it.
HTML:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="showhideJQuery.js"></script>
</head>
<style>
.showhide {
width:500px;
height:200px;
margin:1em .5em;
}
.showhide h3 {
margin: 0;
padding: .25em;
background:#0033CC;
border-top:1px solid #666666;
border-bottom:1px solid #666666;
}
.showhide div {
padding: .5em .25em;
}
</style>
<body>
<div class="showhide">
<h3>Title 1</h3>
<div>
<ol>
<li>Hey!</li>
<div class="showhide">
<h3>Another one?!</h3>
<div>YES!</div>
</div>
</ol>
</div>
</div>
</body>
</html>
JQuery
$(document).ready(function(){
$('div.showhide:eq(0)> div').hide();
$('div.showhide:eq(0)> h3').click(function() {
$(this).next().slideToggle('fast');
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我希望这就是您正在寻找的。
工作演示
I hope this is what you are looking for.
Working demo
通过向要触发显示/隐藏的项目以及要显示/隐藏的元素添加类属性,您可以执行以下操作:
HTML:
JS:
这还使您可以灵活地使用不同的元素来包含隐藏的内容和哪个元素触发该操作。
希望这有帮助。
By adding class attributes to the item you want to trigger the show/hide and the element you want shown / hidden you can do something like this:
HTML:
JS:
This also gives you the flexibility to use different elements to contain your hidden content and which element triggers the action.
Hope this helps.
如果您去掉 jquery 选择器中的
:eq(0)
,它会执行您想要的操作吗?If you get rid of the
:eq(0)
in your jquery selectors, does it do what you want it to?