jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭) 【转载】

1ExpandedBlockStart.gifContractedBlock.gif$(document).ready(function()dot.gif{
 2ExpandedSubBlockStart.gifContractedSubBlock.gif      $('#tabs').tabs(dot.gif{add:addEventHandler});  //给tabs块绑定addEventHandler事件
 3InBlock.gif      $('#newtabs').click(addTab);
 4InBlock.gif
 5ExpandedBlockEnd.gif}
)
 6None.gif
 7None.gifvar tabCounter = 1;        
 8ExpandedBlockStart.gifContractedBlock.giffunction addTab()dot.gif{
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    if(tabCounter > 6)dot.gif{
10InBlock.gif        alert('tabs can not more than 6!');
11InBlock.gif        return;
12ExpandedSubBlockEnd.gif    }

13InBlock.gif    $('<div id="new-tab-'+tabCounter+'">'+'New tab'+tabCounter+'</div>').appendTo('#tabs');
14InBlock.gif    $('#tabs').tabs("add","#new-tab-"+tabCounter,'New tab'+tabCounter);
15InBlock.gif    tabCounter++;
16ExpandedBlockEnd.gif}

17ExpandedBlockStart.gifContractedBlock.giffunction addEventHandler(event,ui)dot.gif{
18InBlock.gif    var li = $(ui.tab).parent();
19InBlock.gif    $('<img src="close.gif"/>'//关闭按钮
20InBlock.gif        .appendTo(li)
21ExpandedSubBlockStart.gifContractedSubBlock.gif        .hover(function()dot.gif{
22InBlock.gif                var img = $(this);
23InBlock.gif                img.attr('src','close_hover2.png');
24ExpandedSubBlockEnd.gif            }
,
25ExpandedSubBlockStart.gifContractedSubBlock.gif            function()dot.gif{
26InBlock.gif                var img = $(this);
27InBlock.gif                img.attr('src','close.png');
28ExpandedSubBlockEnd.gif            }

29InBlock.gif        )
30ExpandedSubBlockStart.gifContractedSubBlock.gif        .click(function()dot.gif{        //关闭按钮,关闭事件绑定
31InBlock.gif            var li = $(ui.tab).parent();
32InBlock.gif      var index = $('#tabs li').index(li.get(0));
33InBlock.gif      $("#tabs").tabs("remove",index);
34InBlock.gif      tabCounter--;
35ExpandedSubBlockEnd.gif        }
);
36ExpandedSubBlockStart.gifContractedSubBlock.gif        $(ui.tab).dblclick(function()dot.gif{   //双击关闭事件绑定
37InBlock.gif            var li = $(ui.tab).parent();
38InBlock.gif      var index = $('#tabs li').index(li.get(0));
39InBlock.gif      $("#tabs").tabs("remove",index);
40InBlock.gif      tabCounter--;
41ExpandedSubBlockEnd.gif        }
);
42ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/lijia7436/archive/2010/03/31/1701193.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值