jQuery实现tabs(标签页/选项卡)Demo

本文介绍了如何使用jQuery实现tabs功能。用户需要下载jquery.min.js文件,并通过滑动鼠标来切换不同标签页,展示相应内容。文章提供了HTML、CSS和JavaScript代码示例。
摘要由CSDN通过智能技术生成

1. 需要下载的文件


jquery.min.js


2. 效果截图


  通过滑动鼠标可以切换不同的tabs,并且显示不同的内容。下面是实现的效果图


3. 代码


  html

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="GB2312" />
    <title>选项卡</title>
    <link href="tabs.css" rel="stylesheet" type="text/css"/>
    <script src="jquery.min.js" type="text/javascript"></script>
    <script src="tabs.js" type="text/javascript"></script>
    
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
Vue3实现Tabs标签可以使用组件化的思路,将每个标签作为一个组件,再将所有标签组合成一个Tabs组件。以下是一个简单的实现: 1. 创建Tabs组件 ``` <template> <div class="tabs"> <div class="tab-header"> <div v-for="(tab, index) in tabs" :key="index" :class="['tab-header-item', { 'active': currentIndex === index }]" @click="changeTab(index)"> {{ tab.title }} </div> </div> <div class="tab-content"> <slot></slot> </div> </div> </template> <script> export default { name: 'Tabs', data() { return { currentIndex: 0, tabs: [] } }, methods: { changeTab(index) { this.currentIndex = index } }, mounted() { this.tabs = this.$children.map((component) => { return { title: component.title } }) } } </script> <style> .tabs .tab-header { display: flex; justify-content: space-between; border-bottom: 1px solid #ccc; } .tabs .tab-header-item { padding: 10px; cursor: pointer; } .tabs .tab-header-item.active { border-bottom: 2px solid #333; } .tabs .tab-content { padding: 10px; } </style> ``` 2. 创建Tab标签组件 ``` <template> <div v-show="isActive"> <slot></slot> </div> </template> <script> export default { name: 'Tab', props: { title: { type: String, required: true } }, data() { return { isActive: false } }, mounted() { this.isActive = this.index === 0 }, computed: { index() { return this.$parent.tabs.length } } } </script> ``` 3. 在Tabs组件中引用Tab标签组件 ``` <template> <div> <Tabs> <Tab title="Tab 1"> <p>Tab 1 content</p> </Tab> <Tab title="Tab 2"> <p>Tab 2 content</p> </Tab> <Tab title="Tab 3"> <p>Tab 3 content</p> </Tab> </Tabs> </div> </template> <script> import Tabs from './Tabs.vue' import Tab from './Tab.vue' export default { name: 'App', components: { Tabs, Tab } } </script> ``` 以上代码实现了一个简单的Tabs标签,可以通过修改样式和添加其他功能来满足实际需求。
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值