jQuery 显示隐藏后的元素
谁能帮助我理解为什么这里的显示按钮没有完成它的工作并显示所有内容?
另外,如果您对隐藏/显示除少数元素之外的所有元素有更好的建议,
我的 JSFiddle 示例更容易理解...... http://jsfiddle.net/qp7HB/
$('#hide').click(function(){
$('body > :not(#reveal)').not(this).hide();
$("#test1").add(this).appendTo("body");
});
$('#reveal').click(function(){
$('body').show();
});
Can anyone help me to understand why the reveal button here is not doing it's job and revealing everything?
Also, if you have a better suggestion for a method to hide / reveal all but a few elements that would appreciated
My JSFiddle example is much easier to understand... http://jsfiddle.net/qp7HB/
$('#hide').click(function(){
$('body > :not(#reveal)').not(this).hide();
$("#test1").add(this).appendTo("body");
});
$('#reveal').click(function(){
$('body').show();
});
因为
body
从未被隐藏,只有它的子项被隐藏。如果元素已被显式隐藏,则显示元素的父元素不会自动显示该元素本身。你可以这样做:DEMO
Because
body
was never hidden, only its children. Showing the parent of an element does not automatically show the element itself if it has been hidden explicitly. You can do:DEMO