jquery:如何将菜单栏链接到选项卡
我有一个菜单栏和选项卡,代码如下:
<div id="menu">
<ul>
<li><a href="#"><span>Inspection</span></a></li>
<ul>
<li><a href="#"><span>show tabs1</span></a></li>
<li><a href="#"><span>show tabs2</span></a></li>
</ul>
</ul>
</div>
<div id="tabs">
<ul>
<li><a href="#tabs1">Inspection Report</a></li>
<li><a href="#tabs2">Input Data</a></li>
</ul>
<div id="tabs1">
bla bla bla
</div>
<div id="tabs2">
blah blah blah
</div>
</div>
我已将下面的代码用于选定的选项卡。 但在我点击 show tabs1
后,实际上显示了 tabs2
:
<script>
$(document).ready(function(){
$("#Tabs").tabs();
$("#menu ul li a").each(function(index){
$(this).click(function(){
$("#Tabs").tabs("select",index);
});
});
});
</script>
I have a menubar and tabs the code like below:
<div id="menu">
<ul>
<li><a href="#"><span>Inspection</span></a></li>
<ul>
<li><a href="#"><span>show tabs1</span></a></li>
<li><a href="#"><span>show tabs2</span></a></li>
</ul>
</ul>
</div>
<div id="tabs">
<ul>
<li><a href="#tabs1">Inspection Report</a></li>
<li><a href="#tabs2">Input Data</a></li>
</ul>
<div id="tabs1">
bla bla bla
</div>
<div id="tabs2">
blah blah blah
</div>
</div>
i have use this code below for selected tabs.
but after i have clicked show tabs1
, actually show tabs2
:
<script>
$(document).ready(function(){
$("#Tabs").tabs();
$("#menu ul li a").each(function(index){
$(this).click(function(){
$("#Tabs").tabs("select",index);
});
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在您终于提供了足够的信息,可以更轻松地帮助您...
将您的 javascript 编辑为以下内容,它仍然使用 jQuery选项卡的选择方法
演示:http://jsfiddle .net/LdDGG
Alternatively, if you plan on adding more
a
elements into your#menu
, you should add IDs to either thea
elements or theul
, like in this demo: http://jsfiddle.net/LdDGG/1/Now that you finally have provided enough information, it's easier to help you...
Edit your javascript to the following, it still uses the select method of jQuery tabs
Demo: http://jsfiddle.net/LdDGG
Alternatively, if you plan on adding more
a
elements into your#menu
, you should add IDs to either thea
elements or theul
, like in this demo: http://jsfiddle.net/LdDGG/1/您的问题不是很清楚,但也许
select
方法就是您正在寻找的。它执行以下操作:
同样来自文档:
以下是其工作原理的演示:http://jsfiddle.net/hP9xb/
Your question isn't very clear, but maybe the
select
method is what you're looking for.It does the following:
Also from the documentation:
Here's a demo of how it works: http://jsfiddle.net/hP9xb/
我们将您的菜单称为“选项卡控制台”,将您的主容器称为“选项卡窗格”。
假设您的选项卡控制台的 html 看起来像这样:
... 并且您的选项卡窗格的外观像这样:
您需要隐藏各种选项卡窗格内容,因此它们不会同时显示。您可以使用 CSS 来做到这一点:
现在我们需要一个脚本来使其全部工作:
We'll call your menu the "tab console" and your main container the "tab pane."
Let's say your tab console's html looks something like this:
... and your tab pane's lookw like this:
You would need to hide the various tab pane contents, so they don't all show at once. You can do this with CSS:
Now we need a script to make it all work: