最后一个项目我做了以下内容:空()追加()附加在循环
$('.document-content').on('input', function() {
var headers;
headers = $('.document-content > h2').each(function() {
var headerId, headerText;
headerId = $(this).attr('id');
headerText = $(this).text();
$('.document-outline').empty().append("<h2><a href='#" + headerId + "'>" + headerText + "</h2>");
});
});
为了避免重复,我加了empty()
但在每个loop
现在只有最后一个项目被附于.document-outline
。
我该如何解决这个问题?