尋找這個小時,我一定在做一些愚蠢的事情。 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