jQuery Mobile默认选项卡 [英] jQuery Mobile default tab
问题描述
我想在jQuery Mobile中设置默认选项卡.
I want to set a default tab in jQuery Mobile.
我的源代码:
<div data-role="tabs" id="tabs">
<div data-role="navbar">
<ul>
<li><a href="#one" id="tabId1" data-ajax="false">one</a></li>
<li><a href="#two" data-ajax="false">two</a></li>
<li><a href="ajax-content.html" data-ajax="false">three</a></li>
</ul>
</div>
<div id="one" class="ui-body-d ui-content">
<h1>First tab contents</h1>
</div>
<div id="two">
<ul data-role="listview" data-inset="true">
<li><a href="#">Acura</a></li>
<li><a href="#">Audi</a></li>
<li><a href="#">BMW</a></li>
<li><a href="#">Cadillac</a></li>
<li><a href="#">Ferrari</a></li>
</ul>
</div>
</div>
$("#tabs").tabs({ active: 0 });
它起作用了,但是没有背景色,因为实际上没有单击第一个选项卡.
It worked but has no background color, because the first tab is not actually clicked.
我要在登录时设置带有背景的默认标签.
I want to set default tab with background when I login in.
推荐答案
要设置活动标签,请尝试:
To set the active tab, try:
$( "#tabs" ).tabs("option", "active", 1);
这是一个有效的 演示
Here is a working DEMO
更新:选项卡按钮上的蓝色背景来自ui-btn-active类.将此类添加到按钮,或者代替设置活动选项卡,而在相应按钮上触发click事件: http://jsfiddle.net/ezanker/c29gd4h6/1/
UPDATE: the blue background on the tab button comes from the class ui-btn-active. Either add this class to the button, or instead of setting the active tab, trigger the click event on the appropriate button: http://jsfiddle.net/ezanker/c29gd4h6/1/
这篇关于jQuery Mobile默认选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!