此代码中的所有内容都有效但浏览器无法在导入新内容后应用jquery函数
html代码:
<div class="id2" > </div>
<div style="clear: both"></div> <br/>
链接
<div class="read">
<table cellpadding="0" cellspacing="0" id="table" width="100%">
</table>
</div>
jquery代码:这段代码 有2个函数第一个函数插入到数据库并导入新内容 第二个函数将从数据库中删除并从删除的表中隐藏tr 当该内容从第一个函数导入时,用户无法从表中删除该问题,jquery函数无法正常工作
/ * delet and hide ** /
$(document).on("click", "#backup", function(){ // when click 'the link' this will import new content and update databace and i use .on() function for it
var s = {
"id": "backup_tables"
};
$.ajax({ // here will do some thing in databacse
url : "function.php",
type : "POST",
data :s,
success : function (data){
$(".id2").stop().stop().html(data).fadeIn(1000).delay(3000).fadeOut(500); // here the massges for user will set in the class "id2"
},
});
var s = {
"id": "backup_readlast"
};
$.ajax({ // hrer will add new content
url : "function.php",
type : "POST",
data :s,
success : function (data){
$(".read table tr:last").after(data); // here will set the new content in the end of table and it's working ,
$("#table tr:last").hide().fadeIn(800); // but The problem that the import content is not applies jquery code
},
beforeSend : function (){
$(".id2").html("<img scr =\"../images/loading.gif\" alt=\"\" />");
}
});
return false;
});
/*** delet and hide ****/
$(".backupdelete").click(function(){ // here this function must be work after import new content ,, but desn't work
var name = $(this).attr("title");
var s = {
"id": "backupdelete",
"id2" : name
};
$.ajax({
url : "function.php",
type : "POST",
data :s,
success : function (data){
$(".id2").stop().stop().html(data).fadeIn(500).delay(2000).fadeOut(500); // here the massges for user will set in the class "id2"
},
beforeSend : function (){
$(".id2").html("<img scr =\"../images/loading.gif\" alt=\"\" />");
}
});
$(this).closest('tr').fadeOut(500);
return false;
});
答案 0 :(得分:0)
因此,在每种情况下都使用on():
/*** delet and hide ****/
$('body').on('click',".backupdelete",function () { // here this function must be work after import new content ,, but desn't work
var name = $(this).attr("title");
var s = {
"id": "backupdelete",
"id2": name
};
$.ajax({
url: "function.php",
type: "POST",
data: s,
success: function (data) {
$(".id2").stop().stop().html(data).fadeIn(500).delay(2000).fadeOut(500); // here the massges for user will set in the class "id2"
},
beforeSend: function () {
$(".id2").html("<img scr =\"../images/loading.gif\" alt=\"\" />");
}
});
$(this).closest('tr').fadeOut(500);
return false;
});