0

私はJQueryIfステートメントを書き込もうとしています。私が達成しようとしているのは、基本的に、特定のdiv(infotab)がクリックされたときに適切なリンク(a)を強調表示することです。あなたが見ることができるようにそれらはすべて隠されていますが、クリックすると、素敵なフェードで見えるようになります。クリックした項目をハイライトしたい。(背景色を、以下のコードの赤など、好きな色に変更してください。)

以下のコードは機能しますが、正しくありません。そのdiv内のすべてのaを強調表示します。クリックされたものを強調表示したいだけです。あなたの助けをありがとうあなたたちは素晴らしいです。

$(document).ready(function () {
    $('#infotab_two_s, #infotab_three_s, #infotab_four_s, #infotab_five_s').hide();
});

$('.subnav_holster li').click(function () {
    var Vinfotab = this.id + '_s';
    $('.infotab:visible').fadeOut('fast', function () {
        $('#' + Vinfotab).fadeIn('fast');
        var Vinfotab_selected = 'Vinfotab:visible';
        $("subnav_holster li a").css({
            "color": "red"
        });
    });
});
4

2 に答える 2

2

クリックliされたものを取得し、その要素にアクセスしますa

$('.subnav_holster li').click(function () {
    var Vinfotab = this.id + '_s';
    var clicked = $(this);
    $('.infotab:visible').fadeOut('fast', function () {
        $('#' + Vinfotab).fadeIn('fast');
        var Vinfotab_selected = 'Vinfotab:visible';
        clicked.find('a').css({
            "color": "red"
        });
    });
});
于 2011-03-26T03:38:06.313 に答える
1

キャッシュthisしてから強調表示する必要があります。

$('.subnav_holster li').click(function () {
    var Vinfotab = this.id + '_s',
        $this = $(this);
    $('.infotab:visible').fadeOut('fast', function () {
        $('#' + Vinfotab).fadeIn('fast');
        var Vinfotab_selected = 'Vinfotab:visible';
        $('.subnav_holster li a').css({
            "background-color": "white" // reset all to default color
        });
        $this.find('a').css({
            "background-color": "red"   // set highlight to this element only
        });
    });
});
于 2011-03-26T03:39:55.310 に答える