admin管理员组

文章数量:1335617

Currently I am using this line of code in my JavaScript

var tabIndex = $(':focus').attr('tabIndex'); 

However this constantly fails to get the active index.

Here is asp:TabContainer header in case this helps. I have also tried document.GetElementById, however to no avail as well.

    <asp:TabContainer ID="AdvOrBasicSearch" runat="server" ActiveTabIndex="0">

Currently I am using this line of code in my JavaScript

var tabIndex = $(':focus').attr('tabIndex'); 

However this constantly fails to get the active index.

Here is asp:TabContainer header in case this helps. I have also tried document.GetElementById, however to no avail as well.

    <asp:TabContainer ID="AdvOrBasicSearch" runat="server" ActiveTabIndex="0">
Share Improve this question asked Sep 9, 2012 at 2:43 NealRNealR 10.7k61 gold badges167 silver badges306 bronze badges 1
  • :focus selects the currently focused element in the page. If you want to select the current selected tab in a tab group, there is surely a better way around. – Fabrício Matté Commented Sep 9, 2012 at 3:06
Add a ment  | 

3 Answers 3

Reset to default 2

They say a picture is worth a thousand words...

I have used jQuery here. With it it is simple to find what you want. Pay attention to the rectangled text in the pic.

Happy coding.

I found this method works much better. I created a variable with the tabContainer itself. Then, I just needed to go inside the variable and pull the value from the _activeTabIndex property.

var tabIndex = $find("AdvOrBasicSearch"); //AdvOrBasicSearch is name of tabContainer
var i = tabIndex._activeTabIndex; 

Get tab index and tab name using javascript

< script type="text/javascript">
        function onTabChanged(sender, e) <br> { <br>
            var curIndex = document.getElementById('lblCurTabNo');<br>
            var curName = document.getElementById('lblCurTabName');<br>
            curIndex.innerHTML = sender.get_activeTabIndex();<br>
            curName.innerHTML = sender.get_activeTab().get_headerText();<br>
        }<br>
    < /script><br><br>

< asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" UseVerticalStripPlacement="false"
            Width="400px" BackColor="ActiveBorder" ForeColor="Green" OnClientActiveTabChanged="onTabChanged"><br>
    ----asp tab control-----------

< /asp:TabContainer>

Tab Index : < asp:Label ID="lblCurTabNo" runat="server" Text="0"></asp:Label><br />

Tab Name :< asp:Label ID="lblCurTabName" runat="server" Text="Personal Info"></asp:Label>

本文标签: javascriptHow to get active tab index from TabContainerStack Overflow