我非常喜欢使用localStorage over cookies,特别是如果你有一个需要与设备无关的应用程序。请注意,下面的代码在不再需要时不会重置localStorage变量。
$(document).ready(function(){
if(localStorage['trthJobStatus']){
$('.trthJobStatus th,.trthJobStatus td').slideToggle('1000');
}
$('.trthJobStatus caption').click(function() {
localStorage['trthJobStatus'] = true;
$('.trthJobStatus th,.trthJobStatus td').slideToggle('1000');
});
});
编辑:这是工作的解决方案!
$(document).ready(function(){
if(window.localStorage.getItem('trthJobStatus') === 'true'){
$('.trthJobStatus th,.trthJobStatus td').slideUp('1000'); }
$('.trthJobStatus caption').click(function(){
if(window.localStorage.getItem('trthJobStatus') === 'true'){ window.localStorage.setItem('trthJobStatus', 'false'); }else{
window.localStorage.setItem('trthJobStatus', 'true');
}
console.log(window.localStorage.getItem('trthJobStatus'));
$('.trthJobStatus th,.trthJobStatus td').slideToggle('1000'); });
});
看一看在此,http://stackoverflow.com/questions/7934139/jquery-slidetoggle-keep-open-until-closed,同样的问题,这已经回答了。可能的重复 –
@loganSarav - 尝试了解决方案,但没有工作:( –