admin管理员组文章数量:1313729
My page looks like this, depending on the index of the selected tab, the Save button needs to behave differently.
This is the jQuery code.
$("#btnSave").click(function () {
var selectedTabIndex = $('#TabStrip').select().index()
if (selectedTabIndex == 1) {
InflowsSave();
}
if (selectedTabIndex == 2) {
OutflowsSave();
}
});
I typed $('#TabStrip').select().index()
within the Inspect Elements console. It doesn't matter which tab is selected, it always returns 2.
>>> $("#TabStrip").select().index()
2
$("#TabStrip").select()
<ul class="t-reset t-tabstrip-items">
<div id="TabStrip-1" class="t-content">
<div id="TabStrip-2" class="t-content t-state-active" style="display:block">
<div id="TabStrip-3" class="t-content">
My page looks like this, depending on the index of the selected tab, the Save button needs to behave differently.
This is the jQuery code.
$("#btnSave").click(function () {
var selectedTabIndex = $('#TabStrip').select().index()
if (selectedTabIndex == 1) {
InflowsSave();
}
if (selectedTabIndex == 2) {
OutflowsSave();
}
});
I typed $('#TabStrip').select().index()
within the Inspect Elements console. It doesn't matter which tab is selected, it always returns 2.
>>> $("#TabStrip").select().index()
2
$("#TabStrip").select()
<ul class="t-reset t-tabstrip-items">
<div id="TabStrip-1" class="t-content">
<div id="TabStrip-2" class="t-content t-state-active" style="display:block">
<div id="TabStrip-3" class="t-content">
Share
Improve this question
edited Aug 26, 2019 at 11:15
Glorfindel
22.7k13 gold badges89 silver badges118 bronze badges
asked Nov 1, 2012 at 4:33
KyleKyle
5,5577 gold badges37 silver badges48 bronze badges
2
- are you working with Telerik Extensions for ASP.NET MVC or Kendo UI Wrappers for ASP.NET MVC ? – kashyapa Commented Nov 1, 2012 at 5:55
- I'm using ASP.NET MVC. Thanks. – Kyle Commented Nov 1, 2012 at 5:59
3 Answers
Reset to default 4if you are using the Telerik Extensions for ASP.NET MVC - have a look at the following documentation on client side event handling of TabStrip
TabStrip Client API & Events
the way to select any Telerik Extension control from JavaScript is as follows:
View:
<%= Html.Telerik().TabStrip()
.Name("TabStrip")
.Items(items =>{/*items definition */})
%>
JavaScript:
<script type="text/javascript">
function getTabStrip(){
var tabStrip = $("#TabStrip").data("tTabStrip");
return tabStrip;
}
</script>
In your scenario in order to know which tab is selected, i would suggest you to listening to tabstrip select event and have a flag set as to which tabstrip is selected. Here is the code to handle client side events:
View:
<%
Html.Telerik().TabStrip()
.Name("TabStrip")
.Items(items =>{/*items definition */})
.ClientEvents(events =>
{
events.OnSelect("Select");
events.OnError("Error");
events.OnContentLoad("ContentLoad");
events.OnLoad(() =>
{%>
function(e) {
/*TODO: actions when the control is loaded.*/
// "this" is the tabstrip.
}
<%});
})
.Render(); %>
Javascript:
<script type="text/javascript">
function Select(e) {
// "this" in this event handler will be the ponent.
// the "e" is an object passed by the jQuery event trigger.
}
function Error(e) {
//code handling the error
}
function ContentLoad(e) {
//code handling the content load
}
</script>
As you can see you can set a flag as to which tab is selected in the Select() method and in your save button click check the flag and act accordingly
If you go through the documentation link i provided at top - it will tell you all the client side events and API exposed by the control
Hope this answers your question
The answer wasn't obvious. Active tabs have the .t-item.t-state-active
css class. So we'd need to find it using jQuery. Hope this helps someone in the future.
var selectedTabIndex = $("#TabStrip > ul").find(".t-item.t-state-active").index();
I did this way, and for me it is working:
var selectedTabId = $("#TabStrip > ul").find(".t-item.t-state-active")[0].id;
本文标签: javascriptIn Telerik TabStrip (MVC)how to get the selected tab indexStack Overflow
版权声明:本文标题:javascript - In Telerik TabStrip (MVC), how to get the selected tab index? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741920213a2404967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论