Button to Trigger Nav-Tab with Twitter Bootstrap

后端 未结 4 2084
遇见更好的自我
遇见更好的自我 2021-02-04 13:07

This button triggers the next tab to load content, but the tab itself does not switch, it remains on the first tab..


4条回答
  •  独厮守ぢ
    2021-02-04 13:52

    By changing 'data-toggle' to 'data-trigger' for the triggering link, the following code can trigger any tab with the same HREF attribute, for all triggers with similar markup.

    (N.B. Selectors are not optimised, it's just a guide to a more flexible solution)

    JS:

    $( '[data-trigger="tab"]' ).click( function( e ) {
        var href = $( this ).attr( 'href' );
        e.preventDefault();
        $( '[data-toggle="tab"][href="' + href + '"]' ).trigger( 'click' );
    } );
    

    HTML:

    Review
    

提交回复
热议问题