jQuery的hide()和.css('display','none')之间的区别?

Eri*_*Red 0 javascript jquery

我已经使用设置CSS样式属性的通用JavaScript更改了几页

element.style.display = "none";
Run Code Online (Sandbox Code Playgroud)

到jQuery的方法

element.hide();
Run Code Online (Sandbox Code Playgroud)

当后退按钮用于返回我的页面时,不再隐藏使用jQuery隐藏的元素.当我使用原始JavaScript设置显示时,隐藏的元素在我返回页面时保持隐藏状态.

是否有一种解决方法允许jQuery的hide()函数以相同的方式工作?

SLa*_*aks 9

jQuery的hide方法执行

        for ( i = 0; i < j; i++ ) {
            this[i].style.display = "none";
        }
Run Code Online (Sandbox Code Playgroud)

你还有其他一些问题.

完整的方法是

hide: function( speed, easing, callback ) {
    if ( speed || speed === 0 ) {
        return this.animate( genFx("hide", 3), speed, easing, callback);

    } else {
        for ( var i = 0, j = this.length; i < j; i++ ) {
            var display = jQuery.css( this[i], "display" );

            if ( display !== "none" ) {
                jQuery.data( this[i], "olddisplay", display );
            }
        }

        // Set the display of the elements in a second loop
        // to avoid the constant reflow
        for ( i = 0; i < j; i++ ) {
            this[i].style.display = "none";
        }

        return this;
    }
},
Run Code Online (Sandbox Code Playgroud)