当链接点击使Div出现并保存隐藏/显示选项在$ .cookie [英] When link clicked make a Div appear and save the hide/show options in $.cookie
本文介绍了当链接点击使Div出现并保存隐藏/显示选项在$ .cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试完成的是当点击链接使一个div可见,并使其保持在那里,直到它被点击,无论窗口刷新。还保存在cookie中的显示/隐藏选项
What i m trying to accomplish is when a link is clicked to make a div visible and make it remain there until its clicked no matter of window refreshes.Also save the show/hide options in a cookie
< ahref="#">Home< / a>
< div id="contentwrapper" style="display:hidden">
holas
< /div>
$(document).ready(function() {
$('a').click(function(){
$('#contentwrapper').fadeIn(300);
$.cookie('content','visible');
var thecontent = $.cookie('content');
});
$('#contentwrapper').click(function(){
$('#contentwrapper').fadeOut(100);
$.cookie('content','hidden');
});
if ( thecontent == 'visible'){
$('#contentwrapper').css("display","block");
};
if (content == 'hidden'){
$('#contentwrapper').fadeOut(200);
};
});
推荐答案
很少事情:
- 没有
显示类型
隐藏
在style =display:hidden
,请改用none
。 - 当页面加载时,
未在
变量到if(thecontent =='visible'){
中定义if($ .cookie('content')=='visible'){
- c> hidden :
if($ .cookie('content')=='hidden'){
- 如果你使用
fadeOut
等从jQuery,你应该使用$('#contentwrapper')。show();
而不是$('#contentwrapper')。css(display,block);
- There is no
display
type ofhidden
as you specify instyle="display:hidden"
, usenone
instead. - When the page loads,
thecontent
variable is not defined inif ( thecontent == 'visible'){
so change it toif ( $.cookie('content') == 'visible'){
- Same thing with the
hidden
:if ($.cookie('content') == 'hidden'){
- If you are using
fadeOut
etc. from jQuery, you should use$('#contentwrapper').show();
instead of$('#contentwrapper').css("display","block");
所有:
$('a').click(function(){
$('#contentwrapper').fadeIn(300);
$.cookie('content','visible');
});
$('#contentwrapper').click(function(){
$('#contentwrapper').fadeOut(100);
$.cookie('content','hidden');
});
if ( $.cookie('content') == 'visible'){
$('#contentwrapper').show();
};
if ($.cookie('content') == 'hidden'){
$('#contentwrapper').fadeOut(200);
};
这篇关于当链接点击使Div出现并保存隐藏/显示选项在$ .cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文