【发布时间】:2014-11-18 15:27:28
【问题描述】:
实际上,我确信以前(某处)曾有人问过这个问题,但我似乎无法以某种方式得到“正常”的答案。
我正在尝试使用 telerik 选项卡控件,并根据单击的链接文本选择打开选项卡。 页面总体布局:
+----------------------------------------+
| HEADER |
+----------------------------------------+
| N |+--------------------------------+ |
| A || Tabstrip | |
| V || | |
| B || | |
| A || | |
| R || | |
| || | |
| || | |
| |+--------------------------------+ |
+----+-----------------------------------+
即我的导航可能如下所示:
+-------------------------------------------------------------------------------------
|
| HEADER
|
+------------------------+------------------------------------------------------------
| Users | __________ __________ ___________
+------------------------+ / Users \ / Products \ / Suppliers \
| Products | / \/____________\/_____________\_______________
+------------------------+ |
| Suppliers | | Tab content here for users page
+------------------------+ |
| Orders | |
+------------------------+ |
| Stock | |
+------------------------+ |
所以,通过点击导航栏中的项目,我希望使相应的选项卡变为活动状态。
我的导航项是使用类似于以下内容的内容创建的:
<li id="users"> <a href="#">Users </a></li>
<li id="products"> <a href="#">Products </a></li>
<li id="suppliers"><a href="#">Suppliers </a></li>
<li id="orders"> <a href="#">Orders </a></li>
<li id="stock"> <a href="#">Stock </a></li>
然后我有一个选项卡控件(它是自动生成的),并且页面检查器在运行时显示
这是实际的选项卡控件。它们是通过以下方式制成的:
@(Html.Kendo().TabStrip()
.Name("tabMain")
.Animation(true)
.Items(items =>
{
/*index 0 */ items.Add().Encoded(false).ImageUrl("~/Content/Images/CLOSE.png").Text("Users    ").Content(Html.Action("Index", "User").ToString());
/*index 1 */ items.Add().Encoded(false).ImageUrl("~/Content/Images/CLOSE.png").Text("Products     ").Content(Html.Action("Index", "Products).ToString());
/*index 2 */ items.Add().Encoded(false).ImageUrl("~/Content/Images/CLOSE.png").Text("Suppliers    ").Content(Html.Action("Index", "Suppliers").ToString());
/*index 3 */ items.Add().Encoded(false).Text("Orders").Content(Html.Action("Index", "Orders").ToString());
/*index 4 */ items.Add().Encoded(false).Text("Stock").Visible(false).Content(Html.Action("Index", "Stock").ToString());
})
)
实际问题
我希望能够按下导航栏上的按钮并显示指定的选项卡/使其处于活动状态。
所以,足够的背景,我目前正在使用 jquery:
$('#stock').click(function(e){
//alert("Stock is what was pressed");
$('#tabMain-1').toggle(); //simply used for testing purposes
$("");
});
尝试选择相应的选项卡。
我的选择器应该是什么来获得唯一的选项卡 id/index/aria-controls(带有值 - 这似乎是他们的“控件的唯一 id”版本)?我应该使用“:Equals”还是“:Contains”?
或者我应该使用完全不同的东西来选择这个标签标题名称吗?
Html,根据要求:
【问题讨论】:
-
#stock突然从哪里来的? -
抱歉,我没有在导航栏中显示所有链接。现在将添加
-
你能提供截图中显示的 HTML 吗?另外,应该根据什么选择
<div>?在它的索引上? -
@Regent 添加(对于它的价值) - 至于你的最后一点,我想我可以选择这个
k-item如果我可以检查它是否有一个aria-controls属性以及tabMain-...的属性值 -
@jbutler483 如果您不想添加与
.kendoToolBar()JS 和 CSS 相关的小提琴以允许查看最终(在 Kendo 修改 DOM 之后)HTML - 这是您的选择。关于aria-controls的定位元素:fiddle example。