Help us understand the problem. What is going on with this article?

jQuery tab切りかえ

More than 3 years have passed since last update.

tab切りかえ

jsめも
each使ったらthisもつかう

js
$(function(){
    $("#price-tab li").click(function(){

        var tab_img = $(this).parent().find("img");
        var _this_img = $(this).find("img");
            // tab_img.attr("src",tab_img.attr("src").replace("-on.", "-off."));
        tab_img.each(function(){
            $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
        });
            _this_img.attr("src", _this_img.attr("src").replace("-off.", "-on."));

        var index = $(this).index();
        $("#price-list li").hide();
        $("#price-list li").eq(index).show();
    });
});

タブ用とコンテンツ用のul,liを用意
相対するタブとコンテンツが同じ順に並ぶようにhtmlをかく

tab押したら、tabのli全部非アクティブの画像に切り替える
そのあと押したとこだけアクティブに

コンテンツも一度全部非表示にする
タブのliが何番目かしらべてそれに対するコンテンツを表示する

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした