区分网格style.visibility和style.display [英] Difference betweet style.visibility and style.display
问题描述
可能重复:
visibility:hidden和display:none之间有什么区别
我在使用JavaScript隐藏/显示 div
标签的示例。
在某些示例中,他们使用 visibility
和一些显示
。
例如
document.getElementById(divhotel)。style.visibility =hidden;
vs
document.getElementById(divhotel)。style.display =none;
两者之间有什么区别?
设置 visibility
到 hidden
,元素不会显示,但仍占用页面上相同的空间。 p>
当您获得 显示
到 none
,元素既不显示也不占用页面上的任何空间。 / p>
我经常发现自己使用 display
,但这取决于您的场景需求。
Possible Duplicate:
What is the difference between visibility:hidden and display:none
I am looking at examples to hide/show div
tags using JavaScript.
In some examples, they use visibility
and in some display
.
e.g.
document.getElementById("divhotel").style.visibility = "hidden";
vs
document.getElementById("divhotel").style.display = "none";
What is the difference between the two?
When you set visibility
to hidden
, the element is not shown but still takes up the same space on the page.
When you get display
to none
, the element is neither shown nor does it take up any space on the page.
More often than not I find myself using display
, but it depends on what your scenario demands.
这篇关于区分网格style.visibility和style.display的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!