javascript 如何在 Kendo UI TabStrip 中获取对当前选定选项卡的引用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14976991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a reference to the currently selected tab in a Kendo UI TabStrip?
提问by pfeds
I'm creating a method to delete a Kendo UI TabStrip Tab based on an 'x' image. I want it to work in the same way as other tab controls (such as Chrome/IE):
我正在创建一种基于“x”图像删除 Kendo UI TabStrip 选项卡的方法。我希望它以与其他选项卡控件(例如 Chrome/IE)相同的方式工作:
- If the active tab is closed then select the next tab (or if it's the last tab then select previous tab).
- If it's not an active tab then ensure the active tab remains open.
- 如果活动选项卡已关闭,则选择下一个选项卡(或者如果它是最后一个选项卡,则选择上一个选项卡)。
- 如果它不是活动选项卡,则确保活动选项卡保持打开状态。
I believe I need to get a reference to the current tab, then check if the tab being deleted is the active tab.
我相信我需要获得对当前选项卡的引用,然后检查被删除的选项卡是否是活动选项卡。
My code at the moment simply closes the tab in relation to the clicked image:
我目前的代码只是关闭与单击的图像相关的选项卡:
function DeleteTab(imgObj) {
var tabStrip = $("#tabstrip").data("kendoTabStrip");
var deleteIndex = $(imgObj).closest("li").index();
tabStrip.remove(deleteIndex);
}
How do I get a reference to the currently selected tab? Can I do this by searching for k-state-active
?
如何获得对当前选定选项卡的引用?我可以通过搜索来做到这一点k-state-active
吗?
回答by Shawn de Wet
tabstrip.select()
will return the currently selected tab.
tabstrip.select()
将返回当前选择的选项卡。
回答by Manuel Sansone
tabStrip.select().index();
Will return currently selected tab index
将返回当前选择的标签索引
回答by Rahul Gupta
To get the currently selected tab of the tabstrip, you can use:
要获取标签条的当前选定选项卡,您可以使用:
var selectedTabElem = $("#tabstripElemId").data('kendoTabStrip').select();// this will be the <li> element that is currently selected
Then one can access the current tab text as below:
然后可以访问当前选项卡文本,如下所示:
var currentSelectedTabText = $(selectedTabElem).children(".k-link").text();