91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JavaScript如何實現table切換的插件封裝

發布時間:2021-10-08 09:38:38 來源:億速云 閱讀:149 作者:小新 欄目:開發技術

這篇文章主要介紹JavaScript如何實現table切換的插件封裝,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

效果圖:

JavaScript如何實現table切換的插件封裝

HTML部分:

<div class="box">
        <div id="tabBox">
            <ul>
                <li class="liStyle">A</li>
                <li>B</li>
                <li>C</li>
            </ul>
            <ol>
                <li class="liStyle">A</li>
                <li>B</li>
                <li>C</li>
            </ol>
        </div>
</div>

css部分:

#tabBox {
            width: 600px;
            height: 450px;
            border: 3px solid #333;
        }
 
        #tabBox>ul {
            width: 100%;
            height: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
 
        #tabBox>ul>li {
            flex: 1;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
            background-color: skyblue;
            font-size: 30px;
        }
 
        #tabBox>ul .liStyle {
            background-color: lime;
        }
 
 
        ol {
            flex: 1;
            width: 600px;
            height: 400px;
        }
 
        ol>li {
            width: 100%;
            height: 100%;
            background-color: #ccc;
            color: #fff;
            font-size: 100px;
 
            display: none;
            justify-content: center;
            align-items: center;
        }
 
        ol>li.liStyle {
            display: flex;
        }

JavaScript構造函數部分:

function fn15() {
            function TabBox(tabbox) {
                this.tabbox = tabbox;
 
                this.tabs = tabbox.querySelectorAll("ul>li")
                this.contents = tabbox.querySelectorAll("ol>li")
            }
 
            TabBox.prototype.startSwitch = function () {
                const tb = this
 
                tb.tabs.forEach(
                    function (tab, index) {
                        tab.onclick = function (e) {
                            tb.tabs.forEach(
                                function (tab) {
                                    tab.classList.remove("liStyle")
                                }
                            )
 
                            tb.contents.forEach(
                                function (con) {
                                    con.classList.remove("liStyle")
                                }
                            )
 
                            tab.classList.add("liStyle")
 
                            tb.contents[index].classList.add("liStyle")
                        }
                    }
                )
            }
            const tabBox = document.querySelector("#tabBox")
 
            const tb = new TabBox(tabBox)
 
            tb.startSwitch()
        }
        // fn15()
 
        // 使用class實現
        function fn16() {
            class TabBox {
                constructor(tabbox) {
                    this.tabbox = tabbox;
                    this.tabs = tabbox.querySelectorAll("ul>li")
                    this.contents = tabbox.querySelectorAll("ol>li")
                }
                startSwitch() {
                    const tb = this
 
                    tb.tabs.forEach(
                        function (tab, index) {
                            tab.onclick = function (e) {
                                tb.tabs.forEach(
                                    function (tab) {
                                        tab.classList.remove("liStyle")
                                    }
                                )
 
                                tb.contents.forEach(
                                    function (con) {
                                        con.classList.remove("liStyle")
                                    }
                                )
 
                                tab.classList.add("liStyle")
 
                                tb.contents[index].classList.add("liStyle")
                            }
                        }
                    )
                }
            }
 
 
            const tabBox = document.querySelector("#tabBox")
 
            const tb = new TabBox(tabBox)
 
            tb.startSwitch()
        }
fn16()

以上是“JavaScript如何實現table切換的插件封裝”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

遵义县| 岳普湖县| 凯里市| 辽阳市| 彭泽县| 宜章县| 太和县| 涞水县| 古蔺县| 余干县| 中超| 蓬安县| 岱山县| 乌拉特中旗| 弥勒县| 凤凰县| 财经| 菏泽市| 晋城| 长兴县| 修文县| 伽师县| 浦东新区| 剑阁县| 营山县| 安康市| 图木舒克市| 济源市| 无锡市| 海晏县| 呼图壁县| 遵义县| 屏山县| 宣城市| 洪洞县| 宁蒗| 佛坪县| 宁津县| 东城区| 金沙县| 徐州市|