用镜头记录,用心灵体验 | 订阅本站 | 所有笔记 | 亲和力设计 | 流量

DB2 学习笔记

博客话题:DB2,Linux,Web,业余无线电,户外,摄影,截拳道,Thankpad,其他

Web

无法覆盖css 中display: none 的问题

在客户端脚本中,我们经常使用对象的CSS 属性style.display 来控制对象在浏览器中的显示与隐藏,一般的习惯是这样写:

  document.getElementById("div").style.display = "none"; // Hide this div
document.getElementById(”div").style.display = ""; // Show the div again
不过我最近遇到一个问题,当已经在CSS文件中为这个对象静态设置了display: "none" 属性,那么上面第二行代码将不起作用,不会按我们的预想将对象显示出来。最后找到了一个解决方法,对于以上情况,以下代码可以实现预期的效果。
 document.getElementById(”div").style.display = "inline"; // Show the div again

display 属性 可以有以下取值,上面的inline 可以换成任何你需要的值。

  • block
  • none
  • inline (this is default)
  • inline-block
  • list-item
  • table-header-group
  • table-footer-group

题外参考:CSS属性Display与Visibility的不同, Ten CSS tricks you may not know

Alex's picture

my email address in picture

搜索|Search

评论|Recent Comments

按月归档|By Month

2009
07
2008
11
10
07
05
04
03
02
01
2007
12
10
07
06
05
04
03
02
01
2006
12
11
10
09
08
07
06
05
04
03
02
01
2005
11
10
09
08
07
04
03
2004
12
11
10
09
08
07
06
05
04
03
02
01
2003
12
10
09
08
06
2002
09
08
04
03
02
2001
12
09
07
06
05

我读|My Books

我的链接|My Links

我的朋友|My Friends

Creative Commons License
This blog is licensed under a Creative Commons License.
Movable Type 4 Logo