Jquery ui 1.7 ui. tabs dynamic addition and closure (button close + double-click close)

Source: Internet
Author: User
Tags closure

jquery UI 1.7 ui.tabs dynamic Add and close (button off + double click off)

$ (document). Ready (function () {
$ (' #tabs '). Tabs ({add:addeventhandler}); Bind addEventHandler Event to tabs block
$ (' #newtabs '). Click (AddTab);
})
var tabcounter = 1;
function AddTab () {
if (Tabcounter > 6) {
Alert (' tabs can not more than 6! ');
Return
}
$ (' <div id= ' new-tab-' +tabcounter+ ' > ' + ' new tab ' +tabcounter+ ' </div> '). Appendto (' #tabs ');
$ (' #tabs '). Tabs ("Add", "#new-tab-" +tabcounter, ' new tab ' +tabcounter);
tabcounter++;
}
function addEventHandler (event,ui) {
var li = $ (ui.tab). parent ();
$ (' ')//Close button
. Appendto (LI)
. Hover (function () {
var img = $ (this);
Img.attr (' src ', ' close_hover2.png ');
},
function () {
var img = $ (this);
Img.attr (' src ', ' close.png ');
}
)
. Click (function () {//Close button, turn off event binding
var li = $ (ui.tab). parent ();
var index = $ (' #tabs Li '). Index (li.get (0));
$ ("#tabs"). Tabs ("Remove", index);
tabcounter--;
});
$ (ui.tab). DblClick (function () {//double-click Close event Binding
var li = $ (ui.tab). parent ();
var index = $ (' #tabs Li '). Index (li.get (0));
$ ("#tabs"). Tabs ("Remove", index);
tabcounter--;
});
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.