我在处理一些jQuery时发现toggle()只在从文档而不是从正文中触发时才切换。
例如
$(document).click(function(){
$('div').toggle();
});
//this toggles
$('body').click(function(){
$('div').toggle();
});
//this doesn't toggle
为什么不与body
切换?
FIDDLE HERE
这是因为当你的div
不在时,body
的height
就是0
,所以当div不在时你不能点击它。
只要给一些height
&width
到您的body
。
body{
height:1000px;
width:1000px;
}
DEMO