twitter-bootstrap 防止引导程序崩溃崩溃

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

prevent bootstrap collapse from collapsing

jquerytwitter-bootstrapcollapse

提问by chris


a have a bootstrap collapse with a button inside the header. On the button is clickEvent
I want to prevent the collapseEvent when clicking the button. Does anyone have a tipp?


a 有一个 bootstrap 折叠,标题内有一个按钮。在按钮上是 clickEvent
我想在单击按钮时防止collapseEvent。有人有tipp吗?

This does not help here

这在这里没有帮助

$('#buttonId').live("click", function (e) {
    e.preventDefault();   
    // some action ...
});

Is there a way to prevent the default collapse action?
Thx

有没有办法阻止默认的折叠动作?
谢谢

回答by A. Wolff

I think you are looking for stopPropagation()method instead:

我认为您正在寻找 stopPropagation()方法:

$('#buttonId').live("click", function (e) {
    e.stopPropagation();   
    // some action ...
});

If your button is a link (<a>tag ), you should prevent default too or use return false;

如果你的按钮是一个链接(<a>标签),你也应该防止默认或使用return false;

BTW, live is deprecated, you should use .on()delegation syntax instead, e.g:

顺便说一句, live 已弃用,您应该使用.on()委托语法,例如:

$(document).on('click', '#buttonId', function(e){
    e.stopPropagation(); 
    // some action ...
});