在我看来,这段代码应该克隆元素#loaded_start_container,并将克隆与其所有子元素一起放入#content-wrapper。
然而,这会创建一个克隆,但不会创建一个子级。如果我只是移动元素而不克隆,它可以工作。
var loaded_content = $('#loaded_start_container').clone().attr('id', 'content_start');
$('#content-wrapper').html(loaded_content);
jQuery 2.0.3
编辑。添加了整个Js
$(function(){
var time_before_load = new Date().getTime();
loadContent('start', function(){
console.log('Now start IS loaded. Evidence ');
console.log($('#loaded_start_container'));
changeContent('start');
loadContent('projects', function(){
loadContent('about', function(){
console.log('All content has been loaded. It took '+ (new Date().getTime() - time_before_load) + ' miliseconds');
});
});
});
$('nav ul li').bind('click', function(){
$('.active_content').removeClass('active_content');
var clicked = $(this).addClass('active_content').attr('id');
changeContent(clicked);
});
});
changeContent = function(source) {
console.log('Changed to ' + source);
var loaded_content = $('#loaded_'+source+'_container').clone().attr('id', 'content_'+source);
$('#content-wrapper').html(loaded_content);
};
loadContent = function(source, callback) {
$('#loaded_'+source+'_container').load(source + '.html', callback());
};