防止引导程序崩溃崩溃 [英] prevent bootstrap collapse from collapsing

查看:30
本文介绍了防止引导程序崩溃崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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 ...
});

这篇关于防止引导程序崩溃崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆