jQuery Tabs - 根据选项卡文本选择选项卡
是否可以根据选项卡标题进行选项卡选择?我当前有一个设置,其中有指向选项卡整数值的链接,但希望能够仅通过字符串值选择选项卡。
当前更改功能
<a href="javascript:changeTab(3)">Application</a>
function changeTab(tabID) {
$('#tabs').tabs('select', tabID);
}
我“希望”能够做什么
<a href="javascript:changeTab('Driver Application')">Application</a>
function changeTab(tabID) {
$('#tabs').tabs('select', tabID);
}
我在 SO 上找到了一个示例,该示例获取选项卡文本的值,但没有使用已知值来确定所选选项卡的地方。
Is it possible to do a tab selection based on the title of the tab? I've got a setup currently that has links pointing to the integer value of the tab, but would like to be able to select the tab just by the String value.
Current change function
<a href="javascript:changeTab(3)">Application</a>
function changeTab(tabID) {
$('#tabs').tabs('select', tabID);
}
What I'd 'like' to be able to do
<a href="javascript:changeTab('Driver Application')">Application</a>
function changeTab(tabID) {
$('#tabs').tabs('select', tabID);
}
I've found an example on SO that gets the VALUE of the text for the tab, but nothing where it uses a known value to determine the tab that is selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个代码。这个想法是根据选项卡的内容获取选项卡的 ID,然后使用现有的选项卡 API 来选择它。
Try this code. The idea is to get the tab's ID based on its contents and then use the existing tabs API to select it.
'select' 方法也可以采用选择器,因此如果您可以忍受使用选项卡的 id,您的代码可能如下所示:
如果您确实想使用选项卡文本本身,则可以找到该选项卡然后工作向后查找 ID...
显然,要调整口味。
The 'select' method can also take a selector, so if you could bear to use the tab's id, your code might look like:
Failing that, if you really want to use the tab text itself, you could find the tab and then work backwards to find the id...
Tweak to taste, obviously.
另请参阅我的 jsfiddle。
Also see my jsfiddle.