How to close tab in bootstrap

藏色散人
Release: 2023-02-10 11:26:48
Original
2216 people have browsed it

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.

How to close tab in bootstrap

#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.

How to close tab in bootstrap

The prerequisite is to introduce jquery:

How to close tab in bootstrap

2. Introduce the plug-in:

How to close tab in bootstrap

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 = ' '; }else{ li_tab = li_tab + ''; } var tabpanel = '
'+ '正在加载...'+ '
'; $('.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(); } }
Copy after login

3. HTML code:

Copy after login

4. The usage method is as follows:

var item = {'id':'1','name':'菜单管理','url':'./menuctrl.html','closable':false}; closableTab.addTab(item);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!