简体   繁体   English

用javascript切换“标签”

[英]Switching “tabs” with javascript

I want to create something like tabs. 我想创建类似标签的东西。 So I have tab itself as 所以我有标签本身

    <div class="tab" >Tab1</div>
    <div class="tab" >Tab2</div>
    <div class="tab" >Tab3</div>

and page content for each tab as 和每个标签的页面内容为

    <div class="pagecontent" >pagecontent for Tab1</div>
    <div class="pagecontent" >pagecontent for Tab2</div>
    <div class="pagecontent" >pagecontent for Tab3</div>

How to make js function in "clever way" so by pressing "tab1", "pagecontent for Tab1" shows and other 2 get hidden? 如何通过“智能方式”使js功能通过按“ tab1”,“ tab1的页面内容”显示而其他2隐藏? Also, number of tabs varies from page to page. 此外,每个页面的标签数也不同。

$(function() {  
    $('.pagecontent').not(':eq(0)').hide();
    $('.tab').click(function() {  
        $('.pagecontent').hide();
        $('.pagecontent').eq($(this).index()).show();
    });  
});

Please see a working demo here > http://jsfiddle.net/Yce32/ 请在此处查看有效的演示> http://jsfiddle.net/Yce32/

Try jQuery UI Tabs: 试试jQuery UI Tabs:

http://jqueryui.com/tabs/ http://jqueryui.com/tabs/

It's "clever way" - you will have add\\delete\\order tabs in a box 这是“明智的方式”-您将在框中添加添加\\删除\\订购标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM