twitter-bootstrap 禁用 Twitter Bootstrap 折叠切换

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

Disable Twitter Bootstrap collapse toggling

javascripttwitter-bootstraptogglecollapse

提问by holyredbeard

I'm using Twitter Boostraps component collapse to reveal some fields which is done by clicking in another field. However, if I click the same field again the other fields get hidden again (i.e toggling).

我正在使用 Twitter Boostraps 组件折叠来显示一些通过单击另一个字段完成的字段。但是,如果我再次单击同一字段,其他字段将再次隐藏(即切换)。

What I want is to disable the toggling so that the fields won't hide when clicking the field a second time. Could this be done easily with some built-in methods or do I need to dive deep into the js file to change it myself?

我想要的是禁用切换,以便在第二次单击该字段时不会隐藏该字段。这是否可以通过一些内置方法轻松完成,或者我是否需要深入研究 js 文件以自己更改它?

回答by Zim

You should be able to do something as simple as..

你应该能够做一些简单的事情......

$('#myDiv').on('hide.bs.collapse', function (e) {
  preventDefault(e);
})

This handles the Bootstrap 3 hide.bs.collapseevent, and prevents the DIV from being hidden again.

这将处理 Bootstrap 3hide.bs.collapse事件,并防止 DIV 再次被隐藏。

Demo: http://bootply.com/75650

演示:http: //bootply.com/75650

回答by Chris

The solution is actually pretty simple and the one marked as correct comes pretty close, here is how you can disable the toggle mechanism:

解决方案实际上非常简单,标记为正确的解决方案非常接近,以下是禁用切换机制的方法:

$('#myDiv').on('hide.bs.collapse', function (e) {
  return isMyDivEnabled(); // true or false
}).on('show.bs.collapse', function (e) {
  return isMyDivEnabled(); // true or false
});

Cheers

干杯

Chris

克里斯