我已经更改了一些页面,不再使用设置CSS样式属性的通用JavaScript。
element.style.display = "none";到jQuery的方法
element.hide();当使用后退按钮返回到我的页面时,使用jQuery隐藏的元素将不再隐藏。当我使用原始JavaScript设置显示时,当我返回页面时,隐藏的元素保持隐藏状态。
有没有办法让jQuery的hide()函数以同样的方式工作?
发布于 2011-01-06 08:14:20
jQuery的hide方法执行
for ( i = 0; i < j; i++ ) {
this[i].style.display = "none";
}你还有一些其他的问题。
完整的方法是
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;
}
},发布于 2011-01-06 08:16:14
有一个很大的不同:
当调用.hide()时,display属性的值被保存在jQuery的数据缓存中,因此当调用.show()时,将恢复初始显示值!
发布于 2011-01-06 08:13:31
都是一样的。jQuery hide将display: none;应用于元素。是什么触发了你的隐藏?它在document.ready中吗??似乎当你点击“返回”时,它不会执行javascript。
https://stackoverflow.com/questions/4610568
复制相似问题