2014-12-30 29 views
0
$('.page').on('click',function(){ 
     $(this).next('.content').css('display','block'); 
      $('body').empty(''); 
      var post = $(this).next('.content').css('display','block'); 
      post.appendTo('body'); 

    }); 

如何清除除.content之外的所有其他内容,所以它就像是不喜欢新页面?我尝试了上面的代码,但是我的逻辑有缺陷。我是jquery的新手。jquery导航使用html()

+1

尝试'$( '页面 ')HTML(' ');',而不是'$(' 主体 ')HTML('');' – Cattla

+0

@Cattla。第一个链接 –

+0

' .empty('');'应该是'.empty();'同时注意'.empty()'body元素,没有其他东西需要检索,所以yoru后者'var post ='不会得到任何东西期望的元素。 –

回答

1

也许你可以在清除页面之前分离节点,然后将其附加回去。

$('.page').on('click',function(){ 
    var content = $(this).next('.content').detach(); 
    $('body').html('').append(content.css('display','block')); 
}); 
+0

看起来不错,但不起作用。我展示了一个空白页面。 –

+0

啊.css()不会触发。 –

+0

如果我想回去怎么办? –

2
$('.page').on('click',function(){ 
    $('body').empty(); 
    // you have just deleted the page, how would you find other objects in the page ? 
    // $(this).next('.content').css('display','block'); 
    // Try to .append new elements to the body 
});