2016-07-14 7 views
0

タブ1からタブ2にタブを変更しようとしていますが、私はstackoverflowに関するいくつかのトピックを見つけましたが、セットアップのhtml/jqueryの/ CSSのこちらのページ:リンク/クリックしてjQuery/Bootstrapタブを変更する

http://ksm.fm/misc/tab-test/

任意のアイデアをどのようにリンクがクリックされたときに「タブ2」のタブの変更を持っていますか?イム私も混乱しているブートストラップを使用しています。

答えて

0

私は、このためのa JSFiddleを作成したより簡単で遊ぶために:

いますが、これにあなたのリンクを変更した場合、それは動作します:

<a href="#" onclick='$(".nav-tabs a[href=\"#B\"]").tab("show")'>Link to tab 2</a> 
0

あなたはまた、ジャバスクリプト/ jqueryののこの小さな作品を試すことができますコード

//Force click method. 
//You can directly put the force click method in the click event handler 
//But I prefer this way for readability and ease of maintenance. 
function toggleClick(elementSelector) { 
    $(elementSelector).click(); 
} 
//Delegated click event on the tab-content section 
//This event will handle all Anchor tags within tab content 
//All you have to do with the markup is add a data-id on the tabs i.e **li > a** which is located in the UL tag 
$(".tab-content").on("click", function(e) { 
    if (e.target && e.target.tagName === "A") { 
     toggleClick("[data-id='" + e.target.hash + "']"); 
     //Without toggleClick method 
     //$("[data-id='" + e.target.hash + "']").click(); 
    } 
}); 

私はまた、あなたが回避するための作業Fiddleを作成しました。

関連する問題