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

JQuery でタブ

More than 5 years have passed since last update.

メモ

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf8" />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title>タブ ケース1</title>
        <script src="/jq-plugin/jquery/jquery-1.10.2.js">
                        <!-- jquery 1.10.2 -->
        </script>
        <script>
            $(document).ready(function() {

                $.fn.tab = function(args) {
                    var p = {};
                    p.tabs = args.tabs || 'a.tab';

                    $(this).click(function() {
                        $(p.tabs).not($(this)).each(function(){
                            $($(this).attr("href")).hide();
                            if ($(this).is(".current")) {
                                $(this).toggleClass("current");
                            }
                        });
                        $($(this).attr("href")).show();
                        if (!$(this).is(".current")) {
                            $(this).toggleClass("current");
                        }
                        return false;
                    });

                };

                // セレクタ変更
                $("#group1 a.tab").tab({
                    tabs : "#group1 a.tab"
                });
                $("#group2 a.tab").tab({
                    tabs : "#group2 a.tab"
                });
            });
        </script>
        <style>
            div.contents {
                width: 500px;
                height: 300px;
                border: 1px solid black;
            }
            div.contents div {
                display: none;
            }
            div.contents div:first-child {
                display: block;
            }
            ul.tab {
                width: 500px;
                border: 1px solid black;
                list-style: none;
                background: gray;
                padding: 0px;
                margin: 0px;
            }
            ul.tab li a {
                color: white;
                background-color: black;
                text-decoration: none;
            }
            ul.tab li a.current {
                color: black;
                background-color: white;
                text-decoration: none;
            }
            ul.tab li {
                display: inline-block;
                width: 70px;
            }
            ul.tab li a {
                width: 100%;
                display: block;
                text-align: center;
                vertical-align: middle;
            }
        </style>
    </head>
    <body>
        <div id="group1">
            <ul class="tab">
                <li>
                    <a class="tab current" href="#tab1" >タブ1</a>
                </li>
                <li>
                    <a class="tab" href="#tab2">タブ2</a>
                </li>
                <li>
                    <a class="tab" href="#tab3">タブ3</a>
                </li>
                <li>
                    <a class="tab" href="#tab4">タブ4</a>
                </li>
                <li>
                    <a class="tab" href="#tab5">タブ5</a>
                </li>
            </ul>
            <div id="contents" class="contents">
                <div id="tab1">
                    内容1
                </div>
                <div id="tab2">
                    内容2
                </div>
                <div id="tab3">
                    内容3
                </div>
                <div id="tab4">
                    内容4
                </div>
                <div id="tab5">
                    内容5
                </div>
            </div>
        </div>
        <div id="group2">
            <ul class="tab">
                <li>
                    <a class="tab current" href="#tab11" >タブ1</a>
                </li>
                <li>
                    <a class="tab" href="#tab12">タブ2</a>
                </li>
                <li>
                    <a class="tab" href="#tab13">タブ3</a>
                </li>
                <li>
                    <a class="tab" href="#tab14">タブ4</a>
                </li>
                <li>
                    <a class="tab" href="#tab15">タブ5</a>
                </li>
            </ul>
            <div id="contents2" class="contents">
                <div id="tab11">
                    内容1
                </div>
                <div id="tab12">
                    内容2
                </div>
                <div id="tab13">
                    内容3
                </div>
                <div id="tab14">
                    内容4
                </div>
                <div id="tab15">
                    内容5
                </div>
            </div>
        </div>
    </body>
</html>
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