【问题标题】:Javascript equivalent of jQuery's .hide() [closed]相当于 jQuery 的 .hide() 的 Javascript [关闭]
【发布时间】:2013-12-06 14:59:19
【问题描述】:

jQuery 的 hide() 的 javascript 等价物是什么?

$("#someID").hide();

等价于

 document.getElementById("#someID").style.visibility="hidden";

document.getElementById("#someID").style.display="none";

【问题讨论】:

  • jQuery 有很好的文档记录 (api.jquery.com/hide)... "匹配的元素将立即隐藏,没有动画。这大致相当于调用 .css( "display", "none" ),只是 display 属性的值保存在 jQuery 的数据缓存中,以便以后可以恢复显示的初始值。 。”
  • 所以很明显你知道如何使用style 对象。那么为什么你没有看到.hide() 之后设置了哪个属性呢?说真的,在问之前要付出一些努力。
  • 你好像是jquery专家@BlueSkies
  • @ParveezAhmed:你为什么这么说?
  • 我也同意parveez

标签: javascript jquery show-hide


【解决方案1】:

the documentation的第一段:

这大致相当于调用 .css( "display", "none" ),只是 display 属性的值保存在 jQuery 的数据缓存中,以便稍后可以将 display 恢复为其初始值。如果一个元素的显示值为 inline 并且被隐藏然后显示,它将再次被显示为 inline。

此外,即使没有记录,也可以通过查看 the source code for show()/hide() 来确认。

【讨论】:

    【解决方案2】:

    document.getElementById("#someID").style.display="none";

    【讨论】:

    • thanxxx @Johan Nordli
    【解决方案3】:

    等于:

    document.getElementById("#someID").style.display="none";
    

    当可见性:隐藏时;被使用的元素仍然占据页面中的空间,但是当你这样做时显示:无;该元素不占用页面中的任何空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多