- Bootstrap 教程
- Bootstrap - 首页
- Bootstrap - 概述
- Bootstrap - 环境搭建
- Bootstrap - RTL(从右到左)
- Bootstrap - CSS 变量
- Bootstrap - 颜色模式
- Bootstrap 布局
- Bootstrap - 断点
- Bootstrap - 容器
- Bootstrap - 网格系统
- Bootstrap - 列
- Bootstrap - 间距
- Bootstrap - 实用工具
- Bootstrap - CSS 网格
- Bootstrap 组件
- Bootstrap - 手风琴
- Bootstrap - 警报
- Bootstrap - 徽章
- Bootstrap - 面包屑
- Bootstrap - 按钮
- Bootstrap - 按钮组
- Bootstrap - 卡片
- Bootstrap - 走马灯
- Bootstrap - 关闭按钮
- Bootstrap - 折叠
- Bootstrap - 下拉菜单
- Bootstrap - 列表组
- Bootstrap - 模态框
- Bootstrap - 导航栏
- Bootstrap - 导航 & 标签
- Bootstrap - 侧边栏
- Bootstrap - 分页
- Bootstrap - 占位符
- Bootstrap - 气泡提示
- Bootstrap - 进度条
- Bootstrap - 滚动侦听
- Bootstrap - 加载动画
- Bootstrap - 提示框
- Bootstrap - 工具提示
- Bootstrap 表单
- Bootstrap - 表单
- Bootstrap - 表单控件
- Bootstrap - 选择框
- Bootstrap - 复选框 & 单选框
- Bootstrap - 范围滑块
- Bootstrap - 输入组
- Bootstrap - 浮动标签
- Bootstrap - 布局
- Bootstrap - 表单验证
- Bootstrap 辅助工具
- Bootstrap - 清除浮动
- Bootstrap - 颜色 & 背景
- Bootstrap - 彩色链接
- Bootstrap - 焦点环
- Bootstrap - 图标链接
- Bootstrap - 位置
- Bootstrap - 比例
- Bootstrap - 堆叠
- Bootstrap - 拉伸链接
- Bootstrap - 文本截断
- Bootstrap - 垂直线
- Bootstrap - 视觉隐藏
- Bootstrap 实用工具
- Bootstrap - 背景
- Bootstrap - 边框
- Bootstrap - 颜色
- Bootstrap - 显示
- Bootstrap - 弹性盒子
- Bootstrap - 浮动
- Bootstrap - 交互
- Bootstrap - 链接
- Bootstrap - 对象适应
- Bootstrap - 不透明度
- Bootstrap - 溢出
- Bootstrap - 位置
- Bootstrap - 阴影
- Bootstrap - 大小
- Bootstrap - 间距
- Bootstrap - 文本
- Bootstrap - 垂直对齐
- Bootstrap - 可见性
- Bootstrap 演示
- Bootstrap - 网格演示
- Bootstrap - 按钮演示
- Bootstrap - 导航演示
- Bootstrap - 博客演示
- Bootstrap - 滑块演示
- Bootstrap - 走马灯演示
- Bootstrap - 页眉演示
- Bootstrap - 页脚演示
- Bootstrap - 英雄图演示
- Bootstrap - 特色演示
- Bootstrap - 侧边栏演示
- Bootstrap - 下拉菜单演示
- Bootstrap - 列表组演示
- Bootstrap - 模态框演示
- Bootstrap - 徽章演示
- Bootstrap - 面包屑演示
- Bootstrap - 超大标题演示
- Bootstrap - 粘性页脚演示
- Bootstrap - 相册演示
- Bootstrap - 登录演示
- Bootstrap - 定价演示
- Bootstrap - 结账演示
- Bootstrap - 产品演示
- Bootstrap - 封面演示
- Bootstrap - 仪表盘演示
- Bootstrap - 粘性页脚导航栏演示
- Bootstrap - 砌体布局演示
- Bootstrap - 启动模板演示
- Bootstrap - RTL 相册演示
- Bootstrap - RTL 结账演示
- Bootstrap - RTL 走马灯演示
- Bootstrap - RTL 博客演示
- Bootstrap - RTL 仪表盘演示
- Bootstrap 有用资源
- Bootstrap - 常见问题解答
- Bootstrap - 快速指南
- Bootstrap - 有用资源
- Bootstrap - 讨论
Bootstrap - 标签插件
标签在章节Bootstrap 导航元素中介绍。通过组合一些数据属性,您可以轻松创建选项卡界面。使用此插件,您可以通过选项卡或分页中的局部内容面板进行切换,甚至可以通过下拉菜单进行切换。
如果您想单独包含此插件功能,则需要tab.js。否则,如章节Bootstrap 插件概述中所述,您可以包含bootstrap.js或最小化版本的bootstrap.min.js。
用法
您可以通过以下两种方式启用标签:
通过数据属性 - 您需要在锚点中添加data-toggle = "tab"或data-toggle = "pill"。
向标签ul添加nav和nav-tabs类将应用 Bootstrap 标签样式,而添加nav和nav-pills类将应用分页样式。
<ul class = "nav nav-tabs"> <li><a href = "#identifier" data-toggle = "tab">Home</a></li> ... </ul>
通过 JavaScript - 您可以使用以下 Javascript 启用标签:
$('#myTab a').click(function (e) { e.preventDefault() $(this).tab('show') })
以下是一个激活单个标签的不同方法的示例:
// Select tab by name $('#myTab a[href = "#profile"]').tab('show') // Select first tab $('#myTab a:first').tab('show') // Select last tab $('#myTab a:last').tab('show') // Select third tab (0-indexed) $('#myTab li:eq(2) a').tab('show')
淡入淡出效果
要为标签获得淡入淡出效果,请向每个.tab-pane添加.fade类。第一个标签面板还必须具有.in类才能正确淡入初始内容:
<div class = "tab-content"> <div class = "tab-pane fade in active" id = "home">...</div> <div class = "tab-pane fade" id = "svn">...</div> <div class = "tab-pane fade" id = "ios">...</div> <div class = "tab-pane fade" id = "java">...</div> </div>
示例
使用数据属性和淡入淡出效果的标签插件示例如下所示:
<ul id = "myTab" class = "nav nav-tabs"> <li class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </li> <li><a href = "#ios" data-toggle = "tab">iOS</a></li> <li class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <li><a href = "#jmeter" tabindex = "-1" data-toggle = "tab">jmeter</a></li> <li><a href = "#ejb" tabindex = "-1" data-toggle = "tab">ejb</a></li> </ul> </li> </ul> <div id = "myTabContent" class = "tab-content"> <div class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </div> <div class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple's mobile version of the OS X operating system used on Apple computers.</p> </div> <div class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java application for load and performance testing.</p> </div> <div class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level applications to be deployed on J2EE compliant Application Server such as JBOSS, Web Logic etc.</p> </div> </div>
方法
.$().tab - 此方法激活标签元素和内容容器。标签应具有data-target或href属性,指向 DOM 中的容器节点。
<ul class = "nav nav-tabs" id = "myTab"> <li class = "active"><a href = "#identifier" data-toggle = "tab">Home</a></li> ..... </ul> <div class = "tab-content"> <div class = "tab-pane active" id = "home">...</div> ..... </div> <script> $(function () { $('#myTab a:last').tab('show') }) </script>
示例
以下示例显示了标签插件方法.tab的使用。在此示例中,激活了第二个标签iOS:
<ul id = "myTab" class = "nav nav-tabs"> <li class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </li> <li><a href = "#ios" data-toggle = "tab">iOS</a></li> <li class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <li> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab"> jmeter </a> </li> <li> <a href = "#ejb" tabindex = "-1" data-toggle = "tab"> ejb </a> </li> </ul> </li> </ul> <div id = "myTabContent" class = "tab-content"> <div class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </div> <div class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple's mobile version of the OS X operating system used on Apple computers.</p> </div> <div class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java application for load and performance testing.</p> </div> <div class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level applications to be deployed on J2EE compliant Application Server such as JBOSS, Web Logic etc.</p> </div> </div> <script> $(function () { $('#myTab li:eq(1) a').tab('show'); }); </script>
事件
下表列出了与标签插件一起使用的事件。此事件可用于挂钩到函数。
事件 | 描述 | 示例 |
---|---|---|
show.bs.tab | 此事件在标签显示时触发,但在新标签显示之前。分别使用event.target和event.relatedTarget来定位活动标签和之前的活动标签(如果可用)。 |
$('a[data-toggle = "tab"]').on('show.bs.tab', function (e) { e.target // activated tab e.relatedTarget // previous tab }) |
shown.bs.tab | 此事件在标签显示后触发。分别使用event.target和event.relatedTarget来定位活动标签和之前的活动标签(如果可用)。 |
$('a[data-toggle = "tab"]').on('shown.bs.tab', function (e) { e.target // activated tab e.relatedTarget // previous tab }) |
示例
以下示例显示了标签插件事件的使用。在此示例中,我们将显示当前和以前访问的标签:
<hr> <p class = "active-tab"><strong>Active Tab</strong>: <span></span></p> <p class = "previous-tab"><strong>Previous Tab</strong>: <span></span></p> <hr> <ul id = "myTab" class = "nav nav-tabs"> <li class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </li> <li><a href = "#ios" data-toggle = "tab">iOS</a></li> <li class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <li> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab">jmeter</a> </li> <li> <a href = "#ejb" tabindex = "-1" data-toggle = "tab">ejb</a> </li> </ul> </li> </ul> <div id = "myTabContent" class = "tab-content"> <div class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </div> <div class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple's mobile version of the OS X operating system used on Apple computers.</p> </div> <div class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java application for load and performance testing.</p> </div> <div class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level applications to be deployed on J2EE compliant Application Server such as JBOSS, Web Logic etc.</p> </div> </div> <script> $(function(){ $('a[data-toggle = "tab"]').on('shown.bs.tab', function (e) { // Get the name of active tab var activeTab = $(e.target).text(); // Get the name of previous tab var previousTab = $(e.relatedTarget).text(); $(".active-tab span").html(activeTab); $(".previous-tab span").html(previousTab); }); }); </script>
广告