Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面加载时立即停止cookie设置_Javascript_Jquery_Cookies - Fatal编程技术网

Javascript 页面加载时立即停止cookie设置

Javascript 页面加载时立即停止cookie设置,javascript,jquery,cookies,Javascript,Jquery,Cookies,一些JS出现问题,页面加载时cookie会立即设置,而只有在我单击关闭框时cookie才会设置 任何帮助都将不胜感激。代码如下: <!doctype html> <html lang="en"> <head> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jq

一些JS出现问题,页面加载时cookie会立即设置,而只有在我单击关闭框时cookie才会设置

任何帮助都将不胜感激。代码如下:

<!doctype html>
<html lang="en">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://resources.site.co.nz/scripts/jquerycookie.js"></script>
    <script type="text/javascript">
    $(function() {
        $('a.close').click(function() {
            $(this).parent().fadeOut(1500);
            $.cookie('hidden', 'true', { expires: null});
            alert($.cookie('hidden'));
            return false;
        });
        if($.cookie('hidden','true')){
            $('#errororganinfoinchide-this').hide();
        }
    });
    </script>
</head>
<body>
    <div id='boxes'>
        <aside class='warning' id='errororganinfoinchide-this'>
            <a href='#errororganinfoinchide-this' class='close'><img src='http://resources.site.co.nz/backgrounds/close.png' /></a>
            <img src='http://resources.site.co.nz/backgrounds/icon_warning.png' class='messageimg' />
            <h4>Warning - Organisation Info</h4>
            <p>Sorry, there was an error opening the "Organisation Info" Box. Please try again later.</p>
        </aside>
    </div>
</body>

$(函数(){
$('a.close')。单击(函数(){
$(this.parent().fadeOut(1500);
$.cookie('hidden','true',{expires:null});
警报($.cookie('hidden'));
返回false;
});
if($.cookie('hidden','true')){
$('#errororganinfoinchide this').hide();
}
});
警告-组织信息
抱歉,打开“组织信息”框时出错。请稍后再试

行“
if($.cookie('hidden','true')){
是否设置cookie而不是读取它

可能应该是这样的


如果($.cookie('hidden')=='true'){

在再次测试之前是否已清除缓存和cookie?不确定是否应将其列为另一个问题。但是否可以获取$(this).parent()。我的意思是,我想获取正在关闭的对象的id,并将其作为cookie的名称。因此,它将是这样的:
$.cookie(“#errorganinfoinchide this”,“true”,“expires:null}”);