当前位置: 首页 > news >正文

jQuery EasyUI 布局 - 创建标签页(Tabs)

jQuery EasyUI 布局 - 创建标签页(Tabs)

jQuery EasyUItabs组件是一个多标签页(tabbed panels)容器,用于在有限空间内显示多个内容面板。用户可以通过点击标题切换面板,常用于后台管理系统的页面切换、表单分组、内容组织等场景。支持关闭标签、嵌套布局、AJAX 加载、拖放排序等高级功能。

Tabs基于panel组件构建,默认垂直标签(top),支持水平/底部/左侧/右侧放置。

官方参考:

  • 教程:https://www.jeasyui.com/tutorial/layout/tabs.php
  • 文档:https://www.jeasyui.com/documentation/tabs.php
  • 在线 Demo:https://www.jeasyui.com/demo/main/index.php?plugin=Tabs
步骤 1: 引入 EasyUI 资源
<linkrel="stylesheet"type="text/css"href="https://www.jeasyui.com/easyui/themes/default/easyui.css"><linkrel="stylesheet"type="text/css"href="https://www.jeasyui.com/easyui/themes/icon.css"><scripttype="text/javascript"src="https://code.jquery.com/jquery-1.12.4.min.js"></script><scripttype="text/javascript"src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
步骤 2: 创建基本的标签页

在容器<div>上添加class="easyui-tabs",子<div>为每个标签页面板。

<divclass="easyui-tabs"style="width:700px;height:400px;"><divtitle="首页"data-options="iconCls:'icon-home',closable:true"style="padding:20px;"><h2>欢迎使用 EasyUI Tabs</h2><p>这是一个基本的标签页示例,支持图标和关闭按钮。</p></div><divtitle="数据表格"data-options="iconCls:'icon-table'"style="padding:20px;"><tableclass="easyui-datagrid"style="width:100%;height:300px;"data-options="url:'datagrid_data.json',fitColumns:true"><thead><tr><thfield="name"width="50">名称</th><thfield="value"width="50"></th></tr></thead></table></div><divtitle="表单"data-options="iconCls:'icon-form',closable:true"><formclass="easyui-form"style="padding:20px;"><divstyle="margin-bottom:10px;"><label>用户名:</label><inputclass="easyui-textbox"name="username"data-options="required:true"></div><divstyle="margin-bottom:10px;"><label>邮箱:</label><inputclass="easyui-textbox"name="email"data-options="validType:'email'"></div></form></div><divtitle="关于"data-options="href:'about.html',iconCls:'icon-help'"><!-- 内容通过 AJAX 从 about.html 加载 --></div></div>
步骤 3: 常用属性说明
属性说明
fit:true自动填充父容器(常用于 layout 的 center 区域)
border:false去除边框,适合嵌入布局
closable:true标签页可关闭(显示 × 按钮)
iconCls标签标题图标
selected:true初始选中该标签页(默认第一个)
href:'url'AJAX 加载标签内容(懒加载,提高性能)
tools自定义工具栏(如刷新、关闭所有按钮)
`tabPosition:'bottomleft
tabWidth:100固定标签宽度(像素)
onSelect切换标签时事件
步骤 4: 完整示例(结合 layout + 动态添加/关闭 + 工具栏)
<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>jQuery EasyUI 标签页(Tabs)</title><linkrel="stylesheet"type="text/css"href="https://www.jeasyui.com/easyui/themes/default/easyui.css"><linkrel="stylesheet"type="text/css"href="https://www.jeasyui.com/easyui/themes/icon.css"><scripttype="text/javascript"src="https://code.jquery.com/jquery-1.12.4.min.js"></script><scripttype="text/javascript"src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script></head><bodyclass="easyui-layout"><divdata-options="region:'north',title:'顶部导航'"style="height:60px;padding:10px;background:#f0f0f0;"><ahref="javascript:void(0)"class="easyui-linkbutton"iconCls="icon-add"onclick="addTab()">新增标签</a><ahref="javascript:void(0)"class="easyui-linkbutton"iconCls="icon-remove"onclick="closeAll()">关闭所有</a></div><divdata-options="region:'center'"><divid="tt"class="easyui-tabs"data-options="fit:true,border:false,tools:'#tab-tools'"><divtitle="首页"data-options="iconCls:'icon-home',closable:true"style="padding:20px;"><h2>首页内容</h2><p>这是一个动态标签页示例,支持添加、关闭和工具栏。</p></div><divtitle="设置"data-options="iconCls:'icon-setting'"style="padding:20px;">系统设置面板。</div></div><divid="tab-tools"><ahref="javascript:void(0)"class="easyui-linkbutton"iconCls="icon-reload"onclick="reloadTab()">刷新</a><ahref="javascript:void(0)"class="easyui-linkbutton"iconCls="icon-remove"onclick="closeCurrent()">关闭当前</a></div></div><script>functionaddTab(){varindex=$('#tt').tabs('getTabIndex',$('#tt').tabs('getSelected'));vartitle='新标签'+(index+1);varcontent='<p>这是动态添加的标签内容。</p><a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeThis()">关闭此标签</a>';$('#tt').tabs('add',{title:title,content:content,closable:true,iconCls:'icon-ok'});}functioncloseAll(){$('.tabs-container .panel').children('.panel-header').find('a.tabs-close').click();}functioncloseCurrent(){vartab=$('#tt').tabs('getSelected');if(tab){varindex=$('#tt').tabs('getTabIndex',tab);$('#tt').tabs('close',index);}}functionreloadTab(){vartab=$('#tt').tabs('getSelected');if(tab){varindex=$('#tt').tabs('getTabIndex',tab);$('#tt').tabs('getTab',index).panel('refresh');}}functioncloseThis(){vartab=$('#tt').tabs('getSelected');if(tab){varindex=$('#tt').tabs('getTabIndex',tab);$('#tt').tabs('close',index);}}</script></body></html>
关键说明
  • 默认行为:标签标题在上方,点击切换面板。
  • 动态操作:使用tabs('add', {title, content/href, closable})添加;tabs('close', index)关闭。
  • 嵌入布局:在 layout 的 center 区域使用fit:true,常用于后台主内容区。
  • AJAX 加载:使用href属性延迟加载外部页面。
  • 工具栏tools属性可自定义按钮,如刷新、关闭。
  • 事件onSelect: function(title, index){ ... }监听切换。
扩展建议
  • 拖放排序:添加$('#tt').tabs({onDragEnd: ...})支持标签拖拽。
  • 嵌套 tabs:在标签内容内再放一个 tabs,实现多级。
  • 底部标签tabPosition:'bottom'

更多示例:

  • 基本 Tabs:https://www.jeasyui.com/demo/main/index.php?plugin=Tabs&theme=default&dir=ltr&pitem=
  • 工具栏 Tabs:https://www.jeasyui.com/easyui/demo/tabs/tools.html
  • 嵌套 Tabs:https://www.jeasyui.com/tutorial/layout/tabs2.php

如果需要动态加载数据、拖放标签、或结合 datagrid 的完整后台 tabs 示例,请提供更多细节!

http://www.jsqmd.com/news/104238/

相关文章:

  • 2026毕设ssm+vue基于框架的宿舍管理系统论文+程序
  • Cursor Rule:AI如何革新代码导航与智能提示
  • 多模态特征强行拼接崩了 补交叉注意力才稳住肺癌诊断模型
  • EmotiVoice实战指南:如何在项目中集成高表现力TTS
  • EmotiVoice语音合成中的韵律建模关键技术解析
  • GEO优化数据统计系统DeepAnaX系统详细介绍:构建企业级AI数据智能分析平台
  • AI应用架构师干货:GNN在医疗病历分析中的架构设计
  • 简历美化vs职业欺诈:员工背景调查如何识别关键风险信号
  • MySQL变长字段的庖丁解牛
  • EmotiVoice语音合成情感渐变功能:从平静到激动平滑过渡
  • xcchat 是一个基于 Django 和 Django Channels 构建的轻量级在线客服系统。它支持实时聊天、人工/机器人客服切换、访客信息追踪和多站点接入
  • 2.3 第一次AI寒冬(1974-1980):计算瓶颈、明斯基的批判与资金撤退
  • 【大模型微调】11-Prefix Tuning技术:分析Prefix Tuning的工作机制
  • EmotiVoice让聋哑人‘听见’文字背后的情绪变化
  • 拒绝复杂!线上业务流程管理:中小团队首选工具推荐
  • Java堆排序
  • 揭秘大数据领域规范性分析的关键流程
  • 为什么越来越多开发者选择EmotiVoice做TTS开发?
  • jQuery EasyUI 布局 - 动态添加标签页(Tabs)
  • 2025年度国产磁悬浮风机核心技术指标实测排名与架构解析报告
  • 电商网站Nginx部署实战:高并发场景优化方案
  • 告别手动测试:MQTT自动化测试脚本开发全攻略
  • 文件上传漏洞检测工具对比:传统VS AI驱动
  • 【大模型微调】10-BitFit技术:介绍BitFit的原理及其在微调中的应用
  • 详解!30+基于YOLO开源框架视频AI算法,覆盖低空经济无人机巡检、海康/大华摄像头,城市综合治理、智慧工地、森林巡检
  • h5嵌入鸿蒙跳转支付宝支付,报错:Syntax error:JSON Parse error:Expected ‘}‘
  • EmotiVoice语音合成系统灰度发布AB测试设计模板
  • 图解B树与B+树:零基础也能懂
  • 传统VS现代:Docker容器启动效率对比实验
  • EmotiVoice语音合成系统日志记录与监控方案设计