简体   繁体   English

禁用Twitter Bootstrap崩溃切换

[英]Disable Twitter Bootstrap collapse toggling

I'm using Twitter Boostraps component collapse to reveal some fields which is done by clicking in another field. 我正在使用Twitter Boostraps组件折叠来显示某些字段,这是通过单击另一个字段来完成的。 However, if I click the same field again the other fields get hidden again (ie toggling). 但是,如果我再次单击同一字段,其他字段将再次隐藏(即切换)。

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文件以自行更改它?

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.collapse event, and prevents the DIV from being hidden again. 这将处理Bootstrap 3 hide.bs.collapse事件,并防止DIV被再次隐藏。

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

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 克里斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM