How to close tabs in bootstrap: 1. Introduce jquery; 2. Reference the "bootstrap-closable-tab" plug-in in the corresponding page; 3. Pass "closeTab:function(item){...}" This method can achieve the effect of closing tabs.
#The operating environment of this article: Windows7 system, bootstrap3, Dell G3 computer.
Bootstrap comes from Twitter and is currently the most popular front-end framework. Bootstrap is based on HTML, CSS, and JavaScript, and it is simple and flexible. During the development process, we only need to add the corresponding class to the DOM element to call it, making Web development faster.
How can bootstrap close tabs?
I found a tab plug-in that can be closed from the Internet: bootstrap-closable-tab plug-in
Reference the bootstrap-closable-tab plug-in in the page to achieve closeability tab page effect.
1. The bootstrap-closable-tab component is a component that can close tab tabs. It is based on jquery and bootstrap; therefore, bootstrap related plug-ins must be introduced.
The prerequisite is to introduce jquery:
2. Introduce the plug-in:
The code is as follows:
//子页面不用iframe,用div展示 var closableTab = { //添加tab addTab:function(tabItem){ //tabItem = {id,name,url,closable} var id = "tab_seed_" + tabItem.id; var container ="tab_container_" + tabItem.id; $("li[id^=tab_seed_]").removeClass("active"); $("div[id^=tab_container_]").removeClass("active"); if(!$('#'+id)[0]){ var li_tab = '<li role="presentation" class="" id="'+id+'"><a href="#'+container+'" role="tab" data-toggle="tab" style="position: relative;padding:2px 20px 2px 15px">'+tabItem.name; if(tabItem.closable){ li_tab = li_tab + '<i class="glyphicon glyphicon-remove small" tabclose="'+id+'" style="position: absolute;right:4px;top: 4px;" οnclick="closableTab.closeTab(this)"></i></a></li> '; }else{ li_tab = li_tab + '</a></li>'; } var tabpanel = '<div role="tabpanel" class="tab-pane" id="'+container+'" style="width: 100%;">'+ '正在加载...'+ '</div>'; $('.nav-tabs').append(li_tab); $('.tab-content').append(tabpanel); $('#'+container).load(tabItem.url,function(response,status,xhr){ if(status=='error'){//status的值为success和error,如果error则显示一个错误页面 $(this).html(response); } }); } $("#"+id).addClass("active"); $("#"+container).addClass("active"); }, //关闭tab closeTab:function(item){ var val = $(item).attr('tabclose'); var containerId = "tab_container_"+val.substring(9); if($('#'+containerId).hasClass('active')){ $('#'+val).prev().addClass('active'); $('#'+containerId).prev().addClass('active'); } $("#"+val).remove(); $("#"+containerId).remove(); } }
3. HTML code:
<div class="iframe_div_wrap"> <!-- 此处是相关代码 --> <ul class="nav nav-tabs" role="tablist"> </ul> <div class="tab-content" style="width:100%;"> </div> <!-- 相关代码结束 --> </div>
4. The usage method is as follows:
var item = {'id':'1','name':'菜单管理','url':'./menuctrl.html','closable':false}; closableTab.addTab(item);
Recommended: "bootstrap tutorial》
The above is the detailed content of How to close tab in bootstrap. For more information, please follow other related articles on the PHP Chinese website!