HTML DOM visibility 屬性
定義和用法
visibility 屬性設(shè)置元素是否可見。
語法:
Object.style.visibility=visible|hidden|collapse
可能的值
值 | 描述 |
---|---|
visible | 默認(rèn)。元素框是可見的。 |
hidden | 元素框不可見,但仍然影響布局。 |
collapse | 當(dāng)在表格元素中使用時(shí),此值可刪除一行或一列,但是它不會(huì)影響表格的布局。被行或列占據(jù)的空間會(huì)留給其他內(nèi)容使用。如果此值被用在其他的元素上,會(huì)呈現(xiàn)為 "hidden"。 |
實(shí)例
下面的例子隱藏一段文本:
<html>
<head>
<script type="text/javascript">
function changeVisibility()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<form>
<input type="button" onclick="changeVisibility()"
value="Hide paragraph" />
</form>
</body>
</html>