I have the following fiddle here: http://jsfiddle.net/9jN8L/
The idea is that sidebar will be shown and if the user clicks the link then it will hide and a cookie will be created and remember that they have hidden it. Should they click it again it will show the sidebar again and delete the cookie (this is why the code is duplicated inside the toggle method functions)
However the sidebar is hidden by default and it doesn't show when the link is clicked after it has been 开发者_如何学运维hidden... Can anyone help? Thanks
Fixed fiddle: http://jsfiddle.net/9jN8L/2/
Replace if($.cookie('HideSidebar', 'Yes'))
by if($.cookie('HideSidebar') == 'Yes')
.
The first condition sets the HideSidebar
cookie to "Yes", while the second (right) method checks whether HideSidebar
equal "Yes".
About your previous (deleted) question: http://jsfiddle.net/Jx3pj/1/. You've forgotten to add the $.Cookie function.
Well, i think if you are going to check the value of the cookie you need to do
if( $.cookie('HideSidebar') )
Instead of
if($.cookie('HideSidebar', 'Yes'))
Because the latter sets the value of the cookie to 'Yes'
精彩评论