javascript 如何从 TabContainer 获取活动标签索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12336124/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:57:58  来源:igfitidea点击:

How to get active tab index from TabContainer

javascriptasp.netajaxtabcontainer

提问by NealR

Currently I am using this line of code in my JavaScript

目前我在我的 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 标头,以防万一。我也尝试过 document.GetElementById,但也无济于事。

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

采纳答案by NealR

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.

我发现这种方法效果更好。我用 tabContainer 本身创建了一个变量。然后,我只需要进入变量内部并从 _activeTabIndex 属性中提取值。

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

回答by deostroll

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.

我在这里使用了 jQuery。有了它,很容易找到你想要的东西。注意图片中的矩形文字。

Happy coding.

快乐编码。

enter image description here

在此处输入图片说明

回答by Jitendra G2

Get tab index and tab name using javascript

使用获取标签索引和标签名称 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 />

标签索引: < asp:Label ID="lblCurTabNo" runat="server" Text="0"></asp:Label><br />

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

标签名称:< asp:Label ID="lblCurTabName" runat="server" Text="Personal Info"></asp:Label>