jQuery $.cookie 不是函数类型错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14618518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:46:45  来源:igfitidea点击:

$.cookie is not a function typeerror

jqueryhtml

提问by sephiith

What does this error mean and how do I fix it?

这个错误是什么意思,我该如何解决?

TypeError: $.cookie is not a function
[Break On This Error]   

$($.cookie("inputFocus")).focus()

Relevant line:

相关线路:

$($.cookie("inputFocus")).focus()

All jQuery code:

所有 jQuery 代码:

<script>
$(document).ready(function() {
    $("#state").change(function () {
    this.form.submit();
})
$($.cookie("inputFocus")).focus()

$("#supplier_name").val($("#supplier_name").val());
$("#aircraft_type").val($("#aircraft_type").val());
var typingTimer;                
var doneTypingInterval = 600;  

$('#supplier_name').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#supplier_name').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
    $.cookie("inputFocus", "#supplier_name"); 
});

$('#aircraft_type').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#aircraft_type').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
    $.cookie("inputFocus", "#aircraft_type"); });
function GetQueryStringParams(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }
}

var state = GetQueryStringParams('state');
var supplier_name = GetQueryStringParams('supplier_name');
var aircraft_type = GetQueryStringParams('aircraft_type');

    if(supplier_name === "" && state === "any" && aircraft_type === "") {
            $('#clear').attr('disabled','disabled');
    }
    $("#clear").click(function() {
    if(state === "any") {
        $("#aircraft_type").val("");
        $("#supplier_name").val("");
    } else {
        $('#state option:selected').remove();
        $("#aircraft_type").val("");
        $("#supplier_name").val("");    
    }
    });

function doneTyping () {
    $("form").submit();
}

});
</script>

回答by tvanfosson

You need to include the jQuery cookie pluginbefore this code snippet.

您需要在此代码片段之前包含 jQuery cookie 插件

回答by Suman K.C

Including jquery file twice(multiple time) also gave same issue in my case.

在我的情况下,包括 jquery 文件两次(多次)也给出了同样的问题。

回答by josh3736

That error means exactly what it says: $.cookiedoes not exist.

该错误的含义正是它所说的:$.cookie不存在。

jQuery core does not include anything related to cookies. There are several cookie librariesthat add a cookiefunction to $. You need to add one to your page first.

jQuery 核心不包含任何与 cookie 相关的内容。有几个 cookie 库可以cookie$. 您需要先添加一个到您的页面。

回答by Rose

It means the library that's supposed to have that function is not loaded. But you can set a cookie using javascript, here:

这意味着没有加载应该具有该功能的库。但是你可以在这里使用 javascript 设置 cookie:

https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie