以前一直show()肯定是display:block,但是今天写jq的时候发现不是这样的,有时候却出现是display:inline。
简单看了下 jquery
此处的实现源码
if ( show ) { // Reset the inline display of this element to learn if it is // being hidden by cascaded rules or not if ( !values[ index ] && elem.style.display === "none" ) { elem.style.display = ""; } // Set elements which have been overridden with display: none // in a stylesheet to whatever the default browser style is // for such an element if ( (elem.style.display === "" && curCSS( elem, "display" ) === "none") || !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { values[ index ] = jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) ); } } else { display = curCSS( elem, "display" ); if ( !values[ index ] && display !== "none" ) { jQuery._data( elem, "olddisplay", display ); } }
发现有缓存原有的 display
值,这样它的show只是显示并不改变你原来display的方式,如果改变的话 那不造成样式的困扰了。相信fadeIn 和fadeOut也是同样的。