如何将jQuery代码附加到动态加载的选项卡

时间:2019-07-03 21:40:48

标签: jquery ajax tabs

我具有工作功能$(“#delete-color-button”)。click ...,我需要使其在动态加载的标签中起作用。我需要将此功能附加到已加载的标签代码上。

$('#colors-1-ul a[class~=active]').first().click()
});

$('#colors-1-ul a').click(function (e) {
e.preventDefault();
var url = $(this).attr("data-url");
var href = this.hash;
var pane = $(this);

$("#colors-1-tab-panes div[class^='tab-pane']").html("<div class=\"tab-loading\" style=\"text-align: center;\"><img src=\"../images/loading.gif\" alt=\"Loading...\" />");

$(href).load(url, function(result){      
pane.tab('show');
myJBox.attach($('#colors-1-tab-panes a'));
});

});

$('#colors-1-1').load($('#colors-1-ul .active a').attr("data-url"), function(result){
$(this).tab('show');
----I need to put some code here to delete function work in dynamically loaded tab
});


$("#delete-color-button").click(function(event){
event.preventDefault();
var post_url = "ajax/delete-text-color.jsp?color=xyz";
var request_method = "get";
var form_data = $(this).serialize();
$.ajax({
url : post_url,
type: request_method,
data : form_data
}).done(function(response){
$("#delete-color-button").html(response);
});
});


...

<span id="delete-color-button">X</span>

非常感谢您

0 个答案:

没有答案