22

我想在引导选项卡中添加一个关闭图标,然后我可以通过单击该图标来关闭该选项卡。

我在下面尝试,但“X”与选项卡标题不在同一行显示。

.close {
    font-size: 20px;
    font-weight: bold;
    line-height: 18px;
    color: #000000;
    text-shadow: 0 1px 0 #ffffff;
    opacity: 0.2;
    filter: alpha(opacity=20);
    text-decoration: none;
    display:inline;
}
.close:hover {
    display:inline;
    color: #000000;
    text-decoration: none;
    opacity: 0.4;
    filter: alpha(opacity=40);
    cursor: pointer;
}

<a id="user-list-tab-li" style="display:inline;" href="#user-list-tab-pane">The tab</a> 
<span class="close">×</span>
4

3 回答 3

31

工作小提琴在这里

 function registerCloseEvent() {

$(".closeTab").click(function () {

    //there are multiple elements which has .closeTab icon so close the tab whose close icon is clicked
    var tabContentId = $(this).parent().attr("href");
    $(this).parent().parent().remove(); //remove li of tab
    $('#myTab a:last').tab('show'); // Select first tab
    $(tabContentId).remove(); //remove respective tab content

});
 }
于 2013-08-07T07:10:00.793 回答
10

尝试将 span-tag 放在 a-tag 内:

<a id="user-list-tab-li" style="display:inline;" href="#user-list-tab-pane">The tab<span class="close">×</span></a> 

如果您使用引导程序,请包含这样的图标:

<i class="icon-remove"></i>
于 2013-08-07T07:15:16.523 回答
0

对Vinod Louis的答案的小调整- 到列表的相对链接,如果它是当前关闭的选项卡,则li只有一个选项卡。show

function close_tab (tab_li)
{
    var tabContentId = $(tab_li).parent().attr("href");
    var li_list = $(tab_li).parent().parent().parent();
    $(tab_li).parent().parent().remove(); //remove li of tab
    if ($(tabContentId).is(":visible")) {
        li_list.find("a").eq(0).tab('show'); // Select first tab
    }
    $(tabContentId).remove(); //remove respective tab content
}

然后附上:

$(".closeTab").click(close_tab(this));

或者:

<button class="close closeTab" type="button" onclick="close_tab(this)" >×</button>
于 2016-05-29T02:16:38.010 回答