【问题标题】:Bootstrap.js tabs doesnt workBootstrap.js 选项卡不起作用
【发布时间】:2013-12-05 14:46:12
【问题描述】:

我对 Bootstrap.js 选项卡很迷茫。我有这个 html:

<ul class="button-menu" id="stores" data-tabs="tabs">

</ul>
<div class="tab-content" id="storesGoods">
    <div class="tab-pane" id="store0">test</div>
    <div class="tab-pane" id="store1">test2</div>   
</div>

我用 JS 生成它的内容

function updateShop(){
    var actualStores = "";
    for (var i=0;i<actualTown.store.length;i++){
        actualStores=actualStores + "<li><a href='#store"+i+"' data-toggle='stores'>"+actualTown.store[i].name+"</a></li>"
        $("#store"+i).html(actualTown.store[i].listGoods());
    };
    $("#stores").html(actualStores);
};

当我通过 Chrome 查看我的 html 时,我看到它生成了这个:

<ul class="button-menu" id="stores" data-tabs="tabs">
    <li><a href="#store0" data-toggle="stores">24/7 Store</a></li>
    <li><a href="#store1" data-toggle="stores">Liquiro</a></li>
</ul>
<div class="tab-content" id="storesGoods">
    <div class="tab-pane" id="store0">
        <p>24/7 Store: All day, all night, every day!</p>
        <table class="table table-condensed">
            <tbody>
                <tr>
                    <th>item</th>
                    <th>price</th>
                    <th></th>
                </tr>
                <tr>
                    <td>Bottled Water</td>
                    <td>0.84</td>
                    <td><a class="buy" onclick="buyToInventory(d1)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Raush Juice</td>
                    <td>0.9</td>
                    <td><a class="buy" onclick="buyToInventory(d2)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Bohemia Chips</td>
                    <td>0.7</td>
                    <td><a class="buy" onclick="buyToInventory(e2)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Vodka Alosuth</td>
                    <td>2.7</td>
                    <td><a class="buy" onclick="buyToInventory(d3)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Pilsner beer (10°)</td>
                    <td>0.8</td>
                    <td><a class="buy" onclick="buyToInventory(d7)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Pilsner beer (12°)</td>
                    <td>0.98</td>
                    <td><a class="buy" onclick="buyToInventory(d8)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Bread</td>
                    <td>1.2</td>
                    <td><a class="buy" onclick="buyToInventory(e1)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Rosito Schnap</td>
                    <td>0.68</td>
                    <td><a class="buy" onclick="buyToInventory(d10)">buy</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="tab-pane" id="store1">
        <p>Liquiro: Bad day? Liquiro will fix that, buy some boost for yourself and some chips.</p>
        <table class="table table-condensed">
            <tbody>
                <tr>
                    <th>item</th>
                    <th>price</th>
                    <th></th>
                </tr>
                <tr>
                    <td>Vodka Alosuth</td>
                    <td>2.7</td>
                    <td><a class="buy" onclick="buyToInventory(d3)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Pilsner beer (10°)</td>
                    <td>0.8</td>
                    <td><a class="buy" onclick="buyToInventory(d7)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Pilsner beer (12°)</td>
                    <td>0.98</td>
                    <td><a class="buy" onclick="buyToInventory(d8)">buy</a>
                    </td>
                </tr>
                <tr>
                    <td>Rosito Schnap</td>
                    <td>0.68</td>
                    <td><a class="buy" onclick="buyToInventory(d10)">buy</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

所以它是按原样生成的,但是切换选项卡不起作用,当我单击 ul #stores 中的某些内容时,它不会更改选项卡,它只是添加到 url www.something.com/#store0 并且没有任何反应。

有谁知道如何使这些标签工作,我完全迷失了。

感谢您的帮助!

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap tabs


    【解决方案1】:

    bootstrap docs 中没有类似data-toggle="store" 的东西,它应该是data-toggle="tab",插件会通过href 属性自行判断哪个是正确的目标。

    他们的例子很简单,照着做就行了。

    【讨论】:

    • 谢谢,它可以工作,但我认为选项卡应该有不同的数据切换,因为我已经有另一个选项卡菜单。 :)
    猜你喜欢
    • 1970-01-01
    • 2012-02-19
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    相关资源
    最近更新 更多