w3cschool案例:

<!DOCTYPE html>
<html>
<body>

<p id="p1">这是一段文本。</p>

<input type="button" value="隐藏文本" onclick="document.getElementById('p1').style.visibility='hidden'" />
<input type="button" value="显示文本" onclick="document.getElementById('p1').style.visibility='visible'" />

</body>
</html>
document.getElementById('p1').style.display=‘none’  也可以使得对象隐藏。但是visibility在隐藏后,对象原先所在的位置并不被清除,style.display=‘none’则清除原对象的位置。

 

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2021-07-28
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
相关资源
相似解决方案