且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery cookie.js来记住隐藏/显示元素?

更新时间:2022-11-10 19:08:27

应该很容易。当你显示div添加一些代码,如:

Should be pretty easy. When you show the div add some code like:

jQuery.cookie('show_desc', 'yep');

...当您隐藏div时:

...and when you hide the div:

jQuery.cookie('show_desc', 'nope');

...然后在您的代码顶部:

...and then at the top of your code where you've got:

jQuery('#group_desciption').hide();

...将其更改为:

var shouldShow = jQuery.cookie('show_desc') == 'yep';
if( shouldShow ) { jQuery('#group_desciption').show(); }
else {             jQuery('#group_desciption').hide(); }

或者:

jQuery('#group_desciption')[jQuery.cookie('show_desc') == 'yep' ? 'show' : 'hide']();

:)