简体   繁体   English

jQuery-类型错误,不是函数

[英]Jquery - type error, is not a function

I am working on a widget that is embedded on a customers website, it loads a jquery file. 我正在处理嵌入在客户网站上的小部件,它将加载一个jquery文件。 however we need to detect if jquery is already loaded on a customers page to avoid conflicts and then not load our own jquery. 但是,我们需要检测是否已经在客户页面上加载了jquery以避免冲突,然后才不加载我们自己的jquery。

As a sidenote the widget works on all versions of jquery. 附带说明,小部件可在所有版本的jquery上使用。 The code being used is... 正在使用的代码是...

 if (typeof jQuery == 'undefined') {
 console.log("NOT LOADED");
 scripts.push("https://d33f10u0pfpplc.cloudfront.net/perun/v1/js/widget/betaV2/jquery-1.8.2-min.js");
 }

This works when tested locally, however when it was rolled out on some sites we got a ... 这在本地测试时有效,但是当它在某些站点上推出时,我们得到了...

type error $tabs(...) is not a function 类型错误$ tabs(...)不是函数

it seems that the jquery on the host sites must not have been fully loaded is my initial theory (could be wrong) 看来宿主网站上的jquery一定不是完全加载的,这是我最初的理论(可能是错误的)

is there a way to improve the jquery detection used above? 有没有一种方法可以改善上面使用的jquery检测? or if you know why it is not working i am happy to learn. 或者,如果您知道为什么它不起作用,我很高兴学习。 thanks 谢谢

First of all, $tabs is not a standard jQuery function. 首先, $tabs不是标准的jQuery函数。 If it's part of a plugin, you need to make sure that's included as well. 如果它是插件的一部分,则还需要确保其中已包含该插件。

Also make sure that jQuery isn't being run in noConflicts mode. 还要确保jQuery不在noConflicts模式下运行。 In that case, jQuery may be defined, but not $ . 在这种情况下,可以定义jQuery ,但不能定义$

Do you check the loading state of the browser? 您是否检查浏览器的加载状态? Javascript is typically executed at the time, when the browser is parsing it. Javascript通常在浏览器解析时执行。 Jquery is a bigger file and sometimes it will execute upcoming code first. jQuery是一个较大的文件,有时它将首先执行即将到来的代码。

To solve it, verify that your own code is executed after dom is loaded: 要解决此问题,请在加载dom后验证是否执行了您自己的代码:

$(function() {
    // your code here
});

Alternative 2 is to check what 备选方案2是检查什么

scripts.push()

exactly does. 确实如此。 It needs to be asynchronous, just only add the file request does not ensure the file is loaded and parsed. 它需要异步,仅添加文件请求并不能确保文件已加载和解析。 Maybe this is your problem. 也许这是你的问题。

Using jQuery in widgets isn't optimal. 在小部件中使用jQuery并不是最佳选择。 Is it possible to write it in native js? 有可能用本机js编写吗?

It's probably not help, but in example at http://www.initializr.com/ 可能无济于事,但例如,在http://www.initializr.com/

jQuery checked like jQuery检查像

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.1.min.js"><\/script>')</script>

Please check your jquery version and your version not have a $tabs jquery function. 请检查您的jquery版本,并且您的版本没有$tabs jquery函数。

Then only you got this type error 然后只有你得到这个类型错误

$tabs(...) is not a function. $ tabs(...)不是函数。

Otherwise try new version of jquery_ui file. 否则,请尝试新版本的jquery_ui文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM