如何使 JQuery Slidedown 中的 DIV 关闭其他 DIV 的单击?
我正在多个 Dvi ID 上执行 Jquery SlideDown,这是我的代码。它工作得很好,但是,我想看看是否可以在打开另一个 div 时关闭打开的 div。注意:我将使用两个以上的 div。
<script type="text/javascript">
$(document).ready(function () {
$('a.slidecontrol').click(function(){
var $this = $(this);
var divID = $this.attr("id").replace("slidecontrol_", "slidedisplay_");
var $div = $('#'+divID);
if ($div.is(':visible')) {
$div.slideUp(500);
} else {
$div.slideDown(500);
}
return false;
});
});
</script>
</head>
<body>
<a href="#" id="slidecontrol_1" class="slidecontrol">Read More</a>
<div id="slidedisplay_1" style="display:none;">Display #1</div>
<hr/>
<a href="#" id="slidecontrol_2" class="slidecontrol">Read More 2</a>
<div id="slidedisplay_2" style="display:none;">Display #2</div>
</body>
</html>
谢谢! 苏菲
I am doing a Jquery SlideDown on Multiple Dvi ID and this is the code that I have. It works really well however, I would like to see if it is possible to make the opened div close as you open another one. Note: I will be using more then two divs.
<script type="text/javascript">
$(document).ready(function () {
$('a.slidecontrol').click(function(){
var $this = $(this);
var divID = $this.attr("id").replace("slidecontrol_", "slidedisplay_");
var $div = $('#'+divID);
if ($div.is(':visible')) {
$div.slideUp(500);
} else {
$div.slideDown(500);
}
return false;
});
});
</script>
</head>
<body>
<a href="#" id="slidecontrol_1" class="slidecontrol">Read More</a>
<div id="slidedisplay_1" style="display:none;">Display #1</div>
<hr/>
<a href="#" id="slidecontrol_2" class="slidecontrol">Read More 2</a>
<div id="slidedisplay_2" style="display:none;">Display #2</div>
</body>
</html>
Thanks!
Sophie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为所有
slidedisplay_
元素指定display
类,并将代码更改为:Give all of your
slidedisplay_
elements the classdisplay
, and change your code to: