Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
Jquery 未定义Getcookie_Jquery_Cookies - Fatal编程技术网

Jquery 未定义Getcookie

Jquery 未定义Getcookie,jquery,cookies,Jquery,Cookies,我正在JQuery页面中使用getcookie值。它在我所有的页面上都有效,除了一个,图书馆: 它表明: Uncaught ReferenceError: getCookie is not defined at generic-scripts.js:2 at dispatch (jquery.min.js:2) at y.handle (jquery.min.js:2) JS结构: function setAgreeCookie() { var expire=n

我正在JQuery页面中使用
getcookie
值。它在我所有的页面上都有效,除了一个,图书馆:

它表明:

Uncaught ReferenceError: getCookie is not defined
    at generic-scripts.js:2
    at dispatch (jquery.min.js:2)
    at y.handle (jquery.min.js:2)
JS结构:

function setAgreeCookie() {
    var expire=new Date();
    expire=new Date(expire.getTime()+777600000000);
    document.cookie="COOKIESCOVID19=aceptada; expires="+expire;
}

$('#acepto-normas-seguridad').click(function(){ 
    setAgreeCookie();
});

   $(window).on('load',function(){
         var myCookie = getCookie("COOKIESCOVID19");

    if (myCookie == null) {
        $('#modalcovid-footer').modal({backdrop: 'static', keyboard: false})  
    }
    else {
        // do cookie exists stuff
    }
});

而且所有代码都在其他页面的相同结构上,因此应该可以工作,但没有。

已解决,需要指定以下内容:

  function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
        end = dc.length;
        }
    }
    // because unescape has been deprecated, replaced with decodeURI
    //return unescape(dc.substring(begin + prefix.length, end));
    return decodeURI(dc.substring(begin + prefix.length, end));
}
您的
getCookie()
函数声明在哪里
getCookie
不是jquery函数-您需要自己创建它。