寻找这个小时,我一定在做一些愚蠢的事情。 jQuery UI v1.11.1。有一个标签小部件,我的第一个标签静态地创建在我的.html。在这第一个选项卡,还有一个按钮来创建新的标签:jQuery UI标签,无法访问新标签中的对象?
function addTab(tabTitle) {
var tabs = $("#tabs").tabs();
var ul = tabs.find("ul");
var id = "tabs-" + tabCounter;
$("<li><a id='" + id + "' href='server.html'>" + tabTitle.val().toUpperCase() + "</a></li>").appendTo(ul);
tabs.tabs("refresh");
var index = $("#tabs a[id='" + id + "']").parent().index();
$("#tabs").tabs({ active: index}); // This successfully selects the new tab visually on the screen
//$("#" + id).click(); // Tried selecting the tab this way also, same issue
var curTabPanel = $('#tabs .ui-tabs-panel:not(.ui-tabs-hide)');
alert(curTabPanel.prop("id")); // This returns the ID of the first tab, not the tab selected on screen, not sure what that implies
$("input").css("display", "none"); // This makes all the input fields disappear on the first tab, not on the tab selected on screen
tabCounter++;
}
正如你所看到的,我已经试过多种方式切换到新标签作为活动标签,但两种方式似乎只允许我在第一个(现在隐藏)选项卡上操作元素 - 即使在视觉上在屏幕上选择了新选项卡。
最终,我需要在文档上定义的所有jQuery处理程序,以准备应用于此新选项卡中的新元素。
我在做什么错?
- 编辑 -
如果我手动创建新的选项卡上的内容(而不是从server.html加载它们),我可以使用jQuery控制的元素。
是否有一个原因,通过外部html文件加载标签内容会使这些元素无法访问jQuery?
感谢
什么是'#tabs'? 'tabCounter'? “HTML”在哪里? 'CSS'? (*如果有*)需要重现..? – 2014-10-06 15:23:20