【发布时间】:2017-08-22 05:35:50
【问题描述】:
我正在研究 JQuery。我收到这个错误。我试图找出根本原因,但我无法找到它。如果有人可以帮助我,那就太好了。
JS 错误:
Uncaught TypeError: $(...).center is not a function
at HTMLDivElement.<anonymous> (myjs:879)
at HTMLDivElement.opt.complete (jquery-1.8.3.js:9154)
at fire (jquery-1.8.3.js:974)
at Object.add [as done] (jquery-1.8.3.js:1020)
at Animation (jquery-1.8.3.js:8719)
at HTMLDivElement.doAnimation (jquery-1.8.3.js:9034)
at Function.dequeue (jquery-1.8.3.js:1895)
at HTMLDivElement.<anonymous> (jquery-1.8.3.js:1938)
at Function.each (jquery-1.8.3.js:611)
at init.each (jquery-1.8.3.js:241)
我的脚本:
function centerdiv() {
$('#id').show(0, function () {
$('#id1').css('z-index','5');
$('body').css('overflow', 'hidden');
$('.class').center();
});
}
所有 JQuery 函数都在工作,我不知道为什么它说 .center 不是一个函数。
【问题讨论】:
-
console.log($('.class')) 说什么?
-
jQuery 里竟然还有
.center()这样的功能?我只从 jQuery UI 脚本中知道.position()。是你自己写的函数? -
是的,在 JQuery @JakubChlebowicz 中有一个名为 .center 的函数
-
我什至在 jQuery API 上都找不到它。 :/ 只要你自己添加到
jQuery.fnprototype里面就可以了 -
@step jQuery 和 jQueryUI 的文档根本没有提到这个
.center函数,谷歌也没有找到它。这表明它是您在某处定义的本地函数。查找包含在其他 JSP 文件中但不在此文件中的库文件。它可能是在您当前未在此页面中加载的某个地方定义的。
标签: javascript jquery