jQuery & CSS - Remove/Add display:none

前端 未结 13 2434
遥遥无期
遥遥无期 2020-12-12 12:37

I have a div with this class :

.news{
  width:710px; 
  float:left;
  border-bottom:1px #000000 solid;
  font-weight:bold;
  display:none;
}
<
13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 13:02

    If you have a lot of elements you would like to .hide() or .show(), you are going to waste a lot of resources to do what you want - even if use .hide(0) or .show(0) - the 0 parameter is the duration of the animation.

    As opposed to Prototype.js .hide() and .show() methods which only used to manipulate the display attribute of the element, jQuery's implementation is more complex and not recommended for a large number of elements.

    In this cases you should probably try .css('display','none') to hide and .css('display','') to show

    .css('display','block') should be avoided, especially if you're working with inline elements, table rows (actually any table elements) etc.

提交回复
热议问题