按ID显示/隐藏/切换多个Divs? [英] Show/Hide/Toggle Multiple Divs By ID?

查看:189
本文介绍了按ID显示/隐藏/切换多个Divs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stackoverflow的好伙伴帮助了我,部分原因是,现在我只需要对终点线稍加推动即可.

The good folks at stackoverflow helped me part of the way with this, now i just need a little push over the finishing line.

我需要有一个切换按钮,该按钮可以在单击时打开div(向下滑动),然后在单击时关闭,也可以使用活动类进行设置.

I need to have a toggle button, that opens div on click (slide down) and then closes on click, pref with an active class too.

但是,如果单击另一个切换按钮,则子div将打开并关闭前一个div(如果已打开).

However, if you click another toggle button that child div opens and closes the previous one, IF it was open.

因此,基本上没有一个div可以同时打开,一次只能打开一个.

So basically none of the opening divs can ever be open at the same time, only one at a time.

我需要通过锚ID来完成此操作,因为开始div与切换按钮无关(它在页面上向下移动了一点)

I need this done by anchor id as the opening div is not related to the toggle button (its down the page a bit)

到目前为止,这是行不通的,但是所有的html都存在.. http://jsfiddle.net /CkTRa/398/

So far that doesn't work, but all the html is there.. http://jsfiddle.net/CkTRa/398/

非常感谢任何人能提供的帮助,搜索了很多内容,而我找到的最接近的是这个

Thank you so much if anyone can help, searched high and low and the nearest i found was this http://andylangton.co.uk/articles/javascript/jquery-show-hide-multiple-elements/ but it doesnt close an already open div when you click a new one.

推荐答案

演示

DEMO

  $("a").click(function(){
    var myelement = $(this).attr("href")
    $(myelement).slideToggle("slow");
    $(".toggle:visible").not(myelement).hide();

  });

这篇关于按ID显示/隐藏/切换多个Divs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆