HTML data-toggle="collapse" 仅在尚未折叠时才折叠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22250574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:09:53  来源:igfitidea点击:

HTML data-toggle="collapse" only collapse if it isn't already

htmltwitter-bootstrapbutton

提问by Philip Scheer

I want to collapse a div with a button if it is not collapsed already. I have a button:

如果尚未折叠,我想用按钮折叠 div。我有一个按钮:

<button data-toggle="collapse" data-target="#aim" ...></button>

and my div:

和我的div

<div id="#aim" class="collapse"></div>

I works great but if the divis already open the button close it.

我工作得很好,但如果div已经打开按钮关闭它。

Is there a chance to get collapse it when it isn't already?

当它还没有崩溃时,是否有机会使其崩溃?

采纳答案by SaschaM78

Remove the #from your <div id="#aim" class="collapse">and it should work. More info about bootstrap's data-toggle attribute can be found here.

#从您的中删除<div id="#aim" class="collapse">它,它应该可以工作。可以在此处找到有关引导程序的数据切换属性的更多信息。

(Previous comment added as possible answer to help close this question).

(先前的评论已添加为可能的答案以帮助关闭此问题)。

回答by Philip Scheer

My solution:

我的解决方案:

<button data-toggle="collapse" data-target="#aim" ...></button>

<div id="aim" class="collapse in"></div>

so when you use collapse ininstead of collapseit only expands and do not minimize itselfs again when it already expanded.

因此,当您使用collapse in而不是collapse它时,它只会扩展,并且在它已经扩展时不会再次最小化自身。

回答by Pickaboo

Use Javascript with on click and hide().

通过单击和隐藏()使用 Javascript。