0

某些 JS 存在问题,其中在页面加载后立即设置 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>

4

1 回答 1

2

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

它可能应该是这样的......

if($.cookie('hidden') == 'true'){

于 2013-01-14T02:42:02.600 回答