【发布时间】:2019-01-07 00:56:22
【问题描述】:
当用户添加新选项卡时,我正在尝试让 jQuery UI 选项卡在浏览器中显示(打开与选项卡关联的面板)。目前这就是我的标签添加功能的样子。
let tabs = $("#tabs")
.tabs({
heightStyle: "content",
})
.on("click", ".delete-tab", function () {
let panelName = $(this).closest("li").children('a').text();
$('#deleteLocationModal').addClass('open');
$('.locationNameHere').text(panelName);
tabDelete = $(this).closest("li");
deleteLocationNum = $(this).attr('data-locNum');
console.log(deleteLocationNum);
});
let locationNum = 1; //Tracks the number of tabs created, NOT the number of tabs on the screen
/**
* Create a new tab
* Create a new panel
*/
$("#addTab").on("click", function (evt) {
/*addTab();*/
locationNum++;
let newTab = (generateTab(locationNum));
$("#tabs").find("#addTab").before(newTab);
let newPanel = (generatePanel(locationNum));
$("#tabs").append(newPanel);
$('#tabs').tabs("refresh");
evt.preventDefault();
});
function generateTab(num) {
return '<li class="tab"><a href="#location_' + num + '">New Location</a> <span data-locNum="' + num + '" class="delete-tab">×</span></li>';
}
我曾尝试查看文档,但并不清楚在创建任何选项卡时显示选项卡的命令是什么。
【问题讨论】:
-
generateTab函数代码在哪里?你可以给你的 html 做广告吗?
-
让我补充一下。
标签: jquery jquery-ui jquery-ui-tabs