防止引导程序崩溃崩溃

问题描述:


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


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?

这在这里没有帮助

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

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

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

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

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

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

如果你的按钮是一个链接( 标签),你也应该阻止 default 或者使用 return false;

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

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

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

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