代码之家  ›  专栏  ›  技术社区  ›  Emilio

在google maps回调函数中未定义Jquery[duplicate]

  •  -1
  • Emilio  · 技术社区  · 6 年前

    我的html代码如下所示:

    我得到一个错误 $ undefined .

    <html>
    <head>
    </head>
    <body>
    <div></div>
    <div></div>
    <div></div>
    <script src="./jquery.js"></script>
    <script>
    function initialize() {
                var input = document.getElementById('where');
                $(input).on('focus', function() { 
                selected = false;
            });
    }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=blablabla&libraries=places&language=en&region=CA&callback=initialize" async defer></script>
    </body>
    </html>
    

    我试着把 async defer ,但是 $ 停留 未定义 .

    我试着改变 function initialize() 对于 var initialize = function() ,但是 $ 停留 未定义 .

    我都试过了,但是 $ 停留 未定义 .

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Monis Mysterion    6 年前

    可能您在加载jQuery之前就已经在代码中使用了它。 所以当你的jQuery代码在那一刻被摩擦时,$就没有意义了。 您以后可以访问,因为文件是在该点之后加载的。 检查脚本加载文件的顺序