twitter-bootstrap Onclick 引导按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16668906/
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
Onclick on bootstrap button
提问by iJade
Ok I'm new to bootstrap themes and all, so was trying to fire a javascript onclick method on the below bootstrap button but couldn't figure out how to do so..
好的,我是引导程序主题的新手,所以我试图在下面的引导程序按钮上触发一个 javascript onclick 方法,但不知道该怎么做..
<a class="btn btn-large btn-success" href="http://twitter.github.io/bootstrap/examples/marketing-narrow.html#">Send Email</a>
Any help would be appreciated..
任何帮助,将不胜感激..
回答by Qurben
Just like any other click event, you can use jQuery to register an element, set an id to the element and listen to events like so:
就像任何其他点击事件一样,您可以使用 jQuery 来注册一个元素,为该元素设置一个 id 并侦听如下事件:
$('#myButton').on('click', function(event) {
event.preventDefault(); // To prevent following the link (optional)
...
});
You can also use inline javascript in the onclick attribute:
您还可以在 onclick 属性中使用内联 javascript:
<a ... onclick="myFunc();">..</a>
回答by Abraham K
<a class="btn btn-large btn-success" id="fire" href="http://twitter.github.io/bootstrap/examples/marketing-narrow.html#">Send Email</a>
$('#fire').on('click', function (e) {
//your awesome code here
})
回答by EpokK
You can use 'onclick' attribute like this :
您可以像这样使用“onclick”属性:
<a ... href="javascript: onclick();" ...>...</a>
回答by Federico Schiocchet
Seem no solutions fix the problem:
似乎没有解决方案可以解决问题:
$(".anima-area").on('click', function (e) {
return false; //return true;
});
$(".anima-area").on('click', function (e) {
e.preventDefault();
});
$(".anima-area").click(function (r) {
e.preventDefault();
});
$(".anima-area").click(function () {
return false; //return true;
});
Bootstrap button always maintain th pressed status and block all .click code. If i remove .click function button comeback to work good.
Bootstrap 按钮始终保持按下状态并阻止所有 .click 代码。如果我删除 .click 功能按钮恢复正常工作。

