0

クリックすると上に移動して、タブが選択されたことを示すタブ付きリンクの行を作成しました。別のタブをクリックすると、現在の「上」タブが「下」状態に戻り、新しく選択されたタブが「上」に変更されます。

これは単純なプロセスで、最後のタブがクリックされるまで機能し、クリックすると「下」の位置に戻りません。

ここでJSフィドルを作成しました:

http://jsfiddle.net/MyPNz/1/

私のJqueryは次のとおりです。

$(function(){

$('a.tab-link-lower').click(function(){

     var index_highest = 0;

     // do this for each of the tabbed/folder links
     $("a.tab-link-lower").each(function(x){

          // remove any styling from all tabs when any tabbed folder is clicked               
          $('#tab'+x+'-lower a').css("color","#6c6a6a"); 
          $('#tab'+x+'-lower').css("font-weight","normal").css("border-bottom","0px").css("background-image","url(http://s23.postimg.org/aunz2qnmf/folder_tab2.png)").css("margin-top","2px");  

          $('#tab'+$(this).attr("id")).css("display","none");

     });

     // add button/link decoration for clicked tab folder when clicked
     $('#'+$(this).attr("id")+'-lower').css("font-weight","bold").css("background-image","url(http://s23.postimg.org/aunz2qnmf/folder_tab2_up.png)").css("color","#ff0000").css("font-size","11px").css("margin-top","-3px").css("border-bottom","1px solid #090");

     // change the color of the a:link once it has been clicked
     $('#tab'+$(this).attr("id")+' a').css("color","#000");

});

ありがとう、

アラン。

4

2 に答える 2

0

問題は、要素 ID が 1 id="tab1-lower" から始まり、その後 each() 関数内で 0 から始まるインデックスである x パラメータを使用していることです。 index と呼ばれる追加の変数を追加しただけで、それぞれの中で x がインクリメントされます() 関数

ここでフィドルを参照してくださいhttp://jsfiddle.net/MyPNz/2/

     // do this for each of the tabbed/folder links
     $("a.tab-link-lower").each(function(x){
          var index = x + 1;
          // remove any styling from all tabs when any tabbed folder is clicked               
          $('#tab'+index+'-lower a').css("color","#6c6a6a"); 
          $('#tab'+index+'-lower').css("font-weight","normal").css("border-bottom","0px").css("background-image","url(http://s23.postimg.org/aunz2qnmf/folder_tab2.png)").css("margin-top","2px");  

          $('#tab'+$(this).attr("id")).css("display","none");

     });
于 2013-09-04T11:35:36.560 に答える