日期:2014-05-16 浏览次数:20390 次
<script> function toggleVisibility(me) { if (me.style.visibility == "hidden") { me.style.visibility = "visible"; } else { me.style.visibility = "hidden"; } } </script> <div onclick="toggleVisibility(this)" style="position:relative">第一行文本将会触发"hidden"和"visible"属性,注意第二行的变化。</div> <div>因为visibility会保留元素的位置,所以虽然第一行看不见了但位置还在,第二行内容不会上下移动。</div>
<script> function toggleDisplay(me) { if (me.style.display == "block") { me.style.display = "inline"; alert("文本现在是:'inline'."); } else { if (me.style.display == "inline") { me.style.display = "none"; alert("文本现在是:'none'. 3秒钟后自动重新显示。"); window.setTimeout("document.getElementById('blueText').style.display='block';", 3000); } else { me.style.display = "block"; alert("文本现在是:'block'."); } } } </script> <div> 在<span id="blueText" onclick="toggleDisplay(this)" style="color:blue;position:relative;cursor:pointer;">蓝色</span>文字上点击来查看效果. </div>
<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> <UL> <LI>将元素设为 block,会在该元素后换行。</LI> <LI>将元素设为 inline,会消除元素换行。</LI> <LI>将元素设为 none,隐藏该元素内容。</LI> </UL>