开门见山讲一下两者的区别

document.getElementById("name").style.display ="none";//隐藏不保留位置

document.getElementById("sex").style.visibility ="hidden";//隐藏占用页面空间

 

读者可以用下面的例子看一下具体结果:

html 部分: 

    <asp:TextBox ID="name" runat="server" Width="100px"  Text="name"></asp:TextBox>

     <asp:TextBox ID="sex"  runat="server" Width="100px"   Text="sex"></asp:TextBox>

     <asp:TextBox ID="pass" runat="server" Width="100px"  Text="pass"></asp:TextBox> 

 <input type ="button" value="隐藏"  onclick =" yincan()"/>

 

js部分: 

     function  yincan()

     {

        document.getElementById("name").style.display ="none";//隐藏不保留位置

        document.getElementById("sex").style.visibility ="hidden";//隐藏占用页面空间

     } 

 

 name被隐藏不保留位置,sex 被隐藏保留位置,效果就是有一块空白部分

相关文章:

  • 2021-05-15
  • 2021-07-30
  • 2021-09-14
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-05
  • 2021-08-01
  • 2022-12-23
  • 2021-10-12
  • 2021-04-16
  • 2021-12-12
相关资源
相似解决方案