使用 Modernizr,但未定义 $
Using Modernizr, but $ is not defined
我正在使用 Modernizr,并且我从以前使用过它的另一个站点复制了我的解决方案,并且没有任何问题。
当我加载页面时,我收到引用错误:$ 未定义。(参考 $(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
函数主要用于加载 polyfill 和兼容性插件等。
只需在自己的 <script>
标记中独立加载 jQuery,然后再对 $
进行任何引用。
如果你确实想继续使用 .load
,你需要将最初的 jQuery 相关代码移动到 .load
完成回调中,这样你就不会尝试调用 jQuery,直到 Modernizr 异步加载它。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- 使用 Modernizr,但未定义 $
- Modernizr / yepno返回“n是未定义的”;在GreaseMonkey中使用时出现错误