按下按钮时如何更改Twitter Bootstrap选项卡?

LA_*_*LA_ 10 jquery jquery-selectors twitter-bootstrap

我需要在按下按钮时更改选项卡,并且应该通过id标识选项卡.以下代码对我不起作用 - 只重新加载页面:

<div class="form-actions">
  <button class="btn btn-primary" id="btn-next">Next</button>
  <button type="reset" class="btn">Clear</button>
</div>
...
<div class="tab-pane active" id="2">
...

$("#btn-next").click(function(event) {
  $('#2').tab('show');
});
Run Code Online (Sandbox Code Playgroud)

bal*_*dre 16

你可以使用这样的东西:

function nextTab(elem) {
  $(elem + ' li.active')
    .next()
    .find('a[data-toggle="tab"]')
    .click();
}
function prevTab(elem) {
  $(elem + ' li.active')
    .prev()
    .find('a[data-toggle="tab"]')
    .click();
}
Run Code Online (Sandbox Code Playgroud)

并使用nextTab('#tab');prevTab('#tab');

带有继续操作的实例:http: //jsbin.com/atinel/9/edit#javascript,html