gpt4 book ai didi

javascript - 使用 Modernizr,但 $ 未定义

转载 作者:行者123 更新时间:2023-11-28 15:29:06 26 4
gpt4 key购买 nike

我正在使用 Modernizr,并且我从另一个网站复制了我的解决方案,我之前在该网站上使用过它并且没有任何问题。

当我加载页面时,我收到 ReferenceError: $ is not Defined。 (引用$(document).ready(function() {...)

现在我知道我明白了,因为 jquery 没有加载,但我无法弄清楚我在这里缺少什么来阻止 jquery 加载。

我错过了什么?

编辑:取出网址并在此处发布原始代码:

<script src="http://www.domain.com/js/modernizer.custom.js"></script>
<script>
//use the modernizr load to load up external scripts. This will load the scripts asynchronously, but the order listed matters. Although it will load all scripts in parallel, it will execute them in the order listed

Modernizr.load([
{
load: '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'
},
{
// test for media query support, if not load respond.js
test : Modernizr.mq('only all'),
// If not, load the respond.js file
nope : '/js/respond.min.js'
}
]);
</script>

最佳答案

不要使用Modernizer.load对于 jQuery - .load函数主要用于加载polyfills和兼容性插件等。

只需在其自己的中独立加载 jQuery <script>在引用 $ 之前标记.

如果您确实想继续使用.load ,您需要将初始 jQuery 相关代码移至 .load完成回调,这样您就不会尝试调用 jQuery,直到 Modernizr 异步加载它。

关于javascript - 使用 Modernizr,但 $ 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28054505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com