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动态添加和删除标签页封装【效果更炫】的更多相关文章

  1. js动态添加和删除标签

    html代码 <h1>动态添加和删除标签</h1> <div id="addTagTest"> <table> <thead& ...

  2. [转] JQuery UI Tabs 动态添加页签,并跳转到新页签

    [From] https://blog.csdn.net/zhangfeng2124/article/details/76672403 需求: 1.tabs默认只有一个页签,但是需要点击某按钮,动态添 ...

  3. jquery 动态添加和删除 ul li列表

    今天需要实现一个jquery动态添加和删除  ul li列表中的li行,自己简单的实现乐一个,分享一下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

  4. jquery mobile Checkbox动态添加刷新及事件绑定

    jquery mobile Checkbox动态添加刷新及事件绑定 在微信项目中,涉及到一个多选功能.数据来自后台数据库,需要动态加载. 项目结构:微信api+web app.使用jquery mob ...

  5. Unity NGUI中动态添加和删除sprite

    (以后,参考链接和作者将在文章首部给出,转载请保留此部分内容) 参考链接:http://www.narkii.com/club/thread-299977-1.html,作者:纳金网 比巴卜: 参考链 ...

  6. 插件~使用ECharts动态在地图上标识点~动态添加和删除标识点

    之前写过一个Echarts的文章,没有基础的同学可以先看这<上一篇>,对于一个地图和说,我们在初始化之后,你可能被在地图上标识出一些点,当然这根据你的业务去标识,而如果每次更新数据都加载全 ...

  7. [Flex] Accordion系列-动态添加或删除Accordion容器中项目

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何使用addChild()和removeCh ...

  8. jQuery ui背景色动态渐变导航菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 原生JS动态添加和删除类

    原生JS动态添加和删除类 由于需要, 给按钮组监听点击事件(要求用事件委托),当有一个按钮被点击时,相应的给该按钮添加一个类(激活类),其他没有点击的按钮就要移出该类 添加和和删除类有三种方法 首先等 ...

随机推荐

  1. c++ 计算程序运行时间

    转载 http://blog.csdn.net/trustbo/article/details/10582287 以前经常听人提起如何计算程序运行时间,给出一系列函数,当时没有注意,随便选了clock ...

  2. sensor调试过程HAL层数据不能被转移到app

    最近调试e-compass传感器,我遇到了一个奇怪的问题,驱动器正常报告数据.但该数据到HAL后该层已经无法上传app. 经debug,我发现这是一个供应商派的代码存在bug,open的fd没有设置N ...

  3. List Set Map用法和区别

    List,Set,Map是否继承自Collection接口? 答:List,Set是,Map不是.如图: Collection ├List │├LinkedList │├ArrayList │└Vec ...

  4. DOM操作应用

    创建元素 document.createElement("li"); 添加节点 oUl.appendChild(oLi); 在某个元素之前插入一个节点 oUl.insertBefo ...

  5. Android 自己定义ScrollView ListView 体验各种纵向滑动的需求

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38950509.本文出自[张鸿洋的博客] 1.概述 群里的一个哥们有个需求是这种: ...

  6. CF 452A(Eevee-直接试)

    A. Eevee time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. JDBC batch批量Statement executeBatch 详细解释

    JDBC提供了数据库batch处理的能力,在数据大批量操作(新增.删除等)的情况下能够大幅度提升系统的性能.我曾经接触的一个项目,在没有採用batch处理时,删除5万条数据大概要半个小时左右,后来对系 ...

  8. earlysuspend调用过程

    1. 电源管理的状态 Android的Linux内核为系统提供了4种电源状态,内核的源码为当中的3种定义了名字和相应的宏定义,名字定义在kernel/power/suspend.c中: constch ...

  9. Visual Studio 使用及调试必知必会

    原文:Visual Studio 使用及调试必知必会   一:C# CODING 技巧 1:TODO 然后 CTRL + W + T,打开任务列表,选中 Comments,就会显示所有待做的任务 2: ...

  10. IDEA内存异常问题

    设置工程运行Server  VM属性 VM options:   -Xms258m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m    如图 :