我看过关于这个主题的其他帖子,但他们总是在重绘时改变元素。我有一个项目列表,我想单击一个并通过 ajax 将其删除,然后重新绘制相同的列表并使其可单击。重绘后的点击不起作用。下面的代码重绘列表一次。然后“listto”项目不再可点击。我认为“开”应该处理这个问题。我怎样才能使这项工作?
$('.listto').on('click',function() {
var tmp = $(this).attr('id').substr(1).split("|");
$.ajax({url: '/contact/removefromlist/'+tmp[0]+'/'+tmp[1],
success: function(data) {
redrawtolist(data,tmp[1])
}
});
});
function redrawtolist(data,item) {
var dat = JSON.parse(data);
var str = "";
$.each(dat, function(index, rel) {
str += '<div id="t'+index+'|'+item+'" class="listto">'+rel+'</div>';
});
$('#tolist').html(str);
}