c.curCSS 不是 jQuery 的函数错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29298462/
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 16:35:12  来源:igfitidea点击:

c.curCSS is not a function bug from jQuery

jquery

提问by Jozsef Naghi

I am getting this errors message in console.

我在控制台中收到此错误消息。

c.curCSS is not a function
...,m,n){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(m...

This my function who does the autocomplete:

这是我的自动完成功能:

function autocomplete_name (name_val, id_val,action, button) {

        $(document).ready(function () {
            $(name_val).autocomplete({
                source: function( request, response ) {
                    $.ajax({
                        url: action,
                        dataType: "json",
                        data: {
                            term: request.term

                        },
                        success: function( data ) {
                            response( $.map( data, function( item ) {
                                return {
                                    label: item.name,
                                    value: item.name,
                                    id: item.id
                                }
                            }));
                        }
                    });
                },
                minLength: 2,
                select: function( event, ui ) {
                    $(id_val).val(ui.item.id);
                    $(name_val).val(ui.item.value);
                    $(button).trigger("click")
                }
            });

        });

}

I have jQuery 1.8.3 version and I do not have access to the file. It is from another server, I just use a link to the library. The function works, but there is no css apply to the results and i am getting that error message in console. YES I saw solutions that I have to modified the library, but I do not have acccess to do that.What should I do in order to make this work.

我有 jQuery 1.8.3 版本,但我无权访问该文件。它来自另一台服务器,我只是使用指向库的链接。该函数有效,但没有适用于结果的 css,我在控制台中收到该错误消息。是的,我看到了必须修改库的解决方案,但我无权这样做。我应该怎么做才能完成这项工作。

回答by Frédéric Hamidi

As a workaround, you could simply redefine $.curCSS()in your module.

作为一种解决方法,您可以简单地$.curCSS()在模块中重新定义。

After including jQuery, write something like:

在包含 jQuery 之后,编写如下内容:

jQuery.curCSS = function(element, prop, val) {
    return jQuery(element).css(prop, val);
};

jQuery UI will end up calling that function afterwards, and the autocomplete widget will work as intended.

之后 jQuery UI 将最终调用该函数,并且自动完成小部件将按预期工作。

Update:I just realized my answer is a quasi-duplicate of Johann Chaves Saborío's answer there. I will leave it here, though, because my function propagates the return value of $.css()to the caller, but his doesn't.

更新:我刚刚意识到我的答案是 Johann Chaves Saborío 在那里的答案的准重复。不过,我将把它留在这里,因为我的函数将 的返回值传播$.css()给调用者,而他的却没有。