twitter-bootstrap Twitter Bootstrap - 打开和关闭 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13271172/
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-10-21 15:40:06  来源:igfitidea点击:

Twitter Bootstrap - Open and close div

twitter-bootstrap

提问by Uli

I'm new to Twitter Bootstrap framework. I would like to open and close a div from a button. How to do that?

我是 Twitter Bootstrap 框架的新手。我想通过按钮打开和关闭 div。怎么做?

Thanks Uli

谢谢乌利

回答by glomad

This is covered explicitly in the bootstrap docs.

这在bootstrap docs 中有明确的介绍。

There is no JS needed (other than including the bootstrap JS.) Everything is done via data attributes.

不需要 JS(除了包含引导 JS 之外)。一切都是通过数据属性完成的。

<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo">
  simple collapsible
</button>

<div id="demo" class="collapse in"> collapse </div>?

Here's a demo: http://jsfiddle.net/3UubF/

这是一个演示:http: //jsfiddle.net/3UubF/

回答by Ed Grosvenor

Do you mean show and hide? If so, I'd just use jQuery. It's Bootstrap's js framework of choice. I'd do something like this...

你的意思是显示和隐藏?如果是这样,我只会使用 jQuery。它是 Bootstrap 的首选 js 框架。我会做这样的事情...

<a class="btn" id="togglemydiv">My Button</a>

$('#togglemydiv').on('click', function()   { $('#targetdiv').toggleClass('hide'); });