首页 > 其他 > 详细

style="visibility: hidden"和 style=“display:none”之间的区别

时间:2017-09-19 23:56:53      阅读:367      评论:0      收藏:0      [点我收藏+]

style=“display:none” 隐藏页面元素:

 

<html>
<head>
<script type="text/javascript">
function removeElement()
{
document.getElementById("p1").style.display="none";
}
</script>
</head>
<body>

<h1>Hello</h1>

<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>

<input type="button" onclick="removeElement()"
value="Do not display paragraph" />

</body>
</html>

 

 

当visibility被设置为"hidden"的时候,元素虽然被隐藏了,但它仍然占据它原来所在的位置。

 

 

通过以下代码,比较两者之间的差异:

<h1>display 属性分别为block, inline, none 值及使用visibility: hidden;的情况调试</h1> 

<P><SPAN id="oSpan" style="background-color: #CFCFCF;">This is a SPAN</SPAN> in a sentence.</P> 

<P> 

    <input type=button value="Inline" onclick="oSpan.style.display=‘inline‘"> 

    <input type=button value="Block" onclick="oSpan.style.display=‘block‘"> 

    <input type=button value="None" onclick="oSpan.style.display=‘none‘"> 

    <input type=button value="Hidden" onclick="oSpan.style.visibility=‘hidden‘">

    <input type=button value="Visible" onclick="oSpan.style.visibility=‘visible‘"> 

</P>

 

style="visibility: hidden"和 style=“display:none”之间的区别

原文:http://www.cnblogs.com/mr-wuxiansheng/p/7554550.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!