jquery-ui-bootstrap动态添加和删除标签页封装【效果更炫】
1、效果图

2、导入js和css
<link rel="stylesheet" href="css/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="font/Font-Awesome/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui-bootstrap/css/custom-theme/jquery-ui-1.10.0.custom.css"/>
<link rel="stylesheet" type="text/css" href="css/default.css"></head>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script src="css/jquery-ui-bootstrap/assets/js/jquery-ui-1.10.0.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/default.js"></script>
default.css是对tabs效果绘制
/*jquery-ui-bootstrap tabs*/
.tabs ul {
/* border-bottom: 3px solid #39aef5!important;*/
}
.tabs ul li:not(:first-child){
padding-right:15px!important; }
.tabs ul li{
border-top:1px solid #ccc!important;
border-left:1px solid #ccc!important;
/*border-bottom: 1px solid #39aef5!important;*/
}
.tabs ul li a{
color:#666!important;
}
.tabs ul li span:hover{
color:#C61010!important;
}
.tabs ul li a:hover,
.tabs ul li:hover,
.tabs ul li:focus{
border-bottom: 0!important;
}
.tabs ul li:last-child{
border-right:1px solid #ccc!important;
}
.tabs ul li.ui-state-active.ui-tabs-active a,
.tabs ul li.ui-state-active.ui-tabs-active span,
.tabs ul li.ui-state-active.ui-tabs-active{
/*border-top:3px solid red!important;*/
background: #39aef5!important;
border-bottom: 2px solid #39aef5!important;
color:#ddd!important;
}
.tabs ul li.ui-state-active.ui-tabs-active a:hover,
.tabs ul li.ui-state-active.ui-tabs-active span:hover
{
color:#fff!important;
}
.tabs ul li .fa-times-circle{
position: absolute;
top: 10px;
right:18px;
}
default.js
$(function(){
var tabs = $( "#tabs3" ).tabs();
var tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='fa fa-times-circle'></span></li>";
$('.menu li').click(function(){
//获取tabs下a[href]的值
var id="#tabs-"+this.id;
//tabs初始化时就有一个li,所以要减1,添加时index会返回-1,再减1变为-2,可根据实际情况而定。这里实际上是通过Id定位#id所在li的位置,然后设置active
var index=$("#tabs3").find(id).index()-1;
$( "#tabs3" ).tabs('option','active',index);
if(index==-2){
addTab(this.innerText,this.id);
}
});
function addTab(tabTitle,id) {
var label = tabTitle,
id = "tabs-" + id,
li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) );
var tabContentHtml = $("."+id).html();
var existing=tabs.find("[id='"+id+"']");
if(existing.length==0){
tabs.find( ".ui-tabs-nav" ).append( li );
tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
tabs.tabs( "refresh" );
}
var index=tabs.find('.ui-tabs-nav li').index(existing);
//添加时总是返回-1
tabs.tabs('option','active',index);
}
// close icon: removing the tab on click
$( "#tabs3" ).on( "click",'span.fa-times-circle', function() {
var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
$( "#" + panelId ).remove();
tabs.tabs( "refresh" );
});
})
3、html片段
<h5>动态标签页</h5>
<ul class="menu">
<li id="menu1">
<a href="#" >菜单1</a>
</li>
<li id="menu2">
<a href="#">菜单2</a>
</li>
<li id="menu3">
<a href="#">菜单3</a>
</li>
</ul>
<div id="tabs3" class="tabs">
<ul>
<li>
<a href="#tabs-4">主页xxxxx</a>
</li> </ul>
<div id="tabs-4">主页内容</div> </div>
<div id="tab_content" style="display: none;">
<div class="tabs-menu1">111</div>
<div class="tabs-menu2">222</div>
<div class="tabs-menu3">333</div>
</div>
jquery-ui-bootstrap动态添加和删除标签页封装【效果更炫】的更多相关文章
- js动态添加和删除标签
html代码 <h1>动态添加和删除标签</h1> <div id="addTagTest"> <table> <thead& ...
- [转] JQuery UI Tabs 动态添加页签,并跳转到新页签
[From] https://blog.csdn.net/zhangfeng2124/article/details/76672403 需求: 1.tabs默认只有一个页签,但是需要点击某按钮,动态添 ...
- jquery 动态添加和删除 ul li列表
今天需要实现一个jquery动态添加和删除 ul li列表中的li行,自己简单的实现乐一个,分享一下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...
- jquery mobile Checkbox动态添加刷新及事件绑定
jquery mobile Checkbox动态添加刷新及事件绑定 在微信项目中,涉及到一个多选功能.数据来自后台数据库,需要动态加载. 项目结构:微信api+web app.使用jquery mob ...
- Unity NGUI中动态添加和删除sprite
(以后,参考链接和作者将在文章首部给出,转载请保留此部分内容) 参考链接:http://www.narkii.com/club/thread-299977-1.html,作者:纳金网 比巴卜: 参考链 ...
- 插件~使用ECharts动态在地图上标识点~动态添加和删除标识点
之前写过一个Echarts的文章,没有基础的同学可以先看这<上一篇>,对于一个地图和说,我们在初始化之后,你可能被在地图上标识出一些点,当然这根据你的业务去标识,而如果每次更新数据都加载全 ...
- [Flex] Accordion系列-动态添加或删除Accordion容器中项目
<?xml version="1.0" encoding="utf-8"?> <!--Flex中如何使用addChild()和removeCh ...
- jQuery ui背景色动态渐变导航菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 原生JS动态添加和删除类
原生JS动态添加和删除类 由于需要, 给按钮组监听点击事件(要求用事件委托),当有一个按钮被点击时,相应的给该按钮添加一个类(激活类),其他没有点击的按钮就要移出该类 添加和和删除类有三种方法 首先等 ...
随机推荐
- 关于AIX lv 4k offset问题初步了解
关于这个问题我们首先来看一下AIX的vg的3种类型: original vg 普通卷组 big vg 大卷组 scalable vg 动态的或者可扩展的卷组 如何快速区分这三组卷组呢? 通过其参数MA ...
- HTML5 Storage API
原文:HTML5 Storage API Web Storage是HTML5引入的一个非常重要的功能,可以在客户端本地存储数据,类似HTML4的cookie,但可实现功能要比cookie强大的多. 在 ...
- Sliverlight之 故事板
见Project19 (1) 将一张图片每隔一秒旋转72度,看看效果是什么样(使用定时器) 说明:前端 <Image.RenderTransform> <RotateTransfor ...
- java命令行HPROF Profiler(转)
The HPROF Profiler The Heap and CPU Profiling Agent (HPROF)是JAVA2 SDK自带的一个简单的profiler代理,它通过与Java Vir ...
- ios-上拉电阻负载许多其他接口
想尝试拉加载意识到有多少开始了他的研究之旅,我看了两天做出最终的界面. 之所以这么慢是由于,我不知道要将上拉出现的view放在哪.就能在scrollView拉究竟部的时候被拉出来.还有就是怎么拉出来之 ...
- li排序
html <ul id="ul1"> <li>9</li> <li>2</li> <li>7</li& ...
- oracle存储过程的例子
oracle存储过程的例子 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的 ...
- struts2充分国际化案例 错误解决
在struts2中须要做国际化的有: jsp页面的国际化,action错误信息的国际化,转换错误信息的国际化.校验错误信息的国际化 在之前的样例中已经做过和国际化相关的样例了,在struts.xml中 ...
- MY WAY程序(十三) 理念和技术
背部,该项目团队去了一半多,我们出差.我将离开之前,闪亮强哥给了我学习技术的列表,以了解它:AngularJs,bootsrap,smartadmin,html5,css3.很多前景的技术.哎,学吧, ...
- HDU 5095 Linearization of the kernel functions in SVM(模拟)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5095 Problem Description SVM(Support Vector Machine) ...