javascript 使用 Modernizr 加载脚本......不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8909862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:57:05  来源:igfitidea点击:

Loading Scripts Using Modernizr... Not Working

javascriptjquerymodernizr

提问by Andy

I'm having problems trying to load scripts using the Modernizr version of yepnope and can't get my head around why they are different. If I load the scripts using yep nope it works fine:

我在尝试使用 yepnope 的 Modernizr 版本加载脚本时遇到问题,并且无法理解它们为何不同。如果我使用 yep nope 加载脚本,它可以正常工作:

<script type="text/javascript" src="/js/yepnope.1.0.2-min.js"></script>
<script type="text/javascript">
yepnope([  
    '/js/fancy-box-2.0.4/jquery.fancybox.css',  
    '/js/jquery-1.7.min.js',  
    '/js/jquery.form-defaults.js',  
    '/js/jquery.cycle.all.js',  
    '/js/jquery.easing.1.3.js',  
    '/js/fancy-box-2.0.4/jquery.fancybox.js',  
    '/js/functions.js',  
    'http://use.typekit.com/uoy8fub.js'
]); 
</script>

But if I trying using the Modernizr packaged version of yep nope I can't get anything to load... Help?

但是,如果我尝试使用 Modernizr 打包版本是的,我无法加载任何内容...帮助?

<script type="text/javascript" src="/js/modernizr-2.0.6.js"></script>
<script type="text/javascript">
Modernizr.load([  
    '/js/fancy-box-2.0.4/jquery.fancybox.css',  
    '/js/modernizr-2.0.6.js',  
    '/js/jquery-1.7.min.js',  
    '/js/jquery.form-defaults.js',  
    '/js/jquery.cycle.all.js',  
    '/js/jquery.easing.1.3.js',  
    '/js/fancy-box-2.0.4/jquery.fancybox.js',  
    '/js/functions.js',  
    'http://use.typekit.com/uoy8fub.js'
]); 
</script>

回答by Ash Clarke

UPDATE: Modernizr.loadhas been deprecated in version 3.0 in favour of using YepNope.js directly.

更新:Modernizr.load已在 3.0 版中弃用,转而直接使用 YepNope.js。

It's worth noting that Modernizr.load just uses the yepnope library and they are interchangeable. e.g.

值得注意的是,Modernizr.load 仅使用 yepnope 库,并且它们是可以互换的。例如

yepnope({
  test : Modernizr.geolocation,
  yep  : 'normal.js',
  nope : ['polyfill.js', 'wrapper.js']
});

Modernizr.load({
  test : Modernizr.geolocation,
  yep  : 'normal.js',
  nope : ['polyfill.js', 'wrapper.js']
});

For yours, try:

对于您的,请尝试:

Modernizr.load({
    load: [  
        '/js/fancy-box-2.0.4/jquery.fancybox.css',  
        '/js/jquery-1.7.min.js',  
        '/js/jquery.form-defaults.js',  
        '/js/jquery.cycle.all.js',  
        '/js/jquery.easing.1.3.js',  
        '/js/fancy-box-2.0.4/jquery.fancybox.js',  
        '/js/functions.js',  
        'http://use.typekit.com/uoy8fub.js'
    ]
}); 

回答by Fabio Buda

Modernizr needs a test to decide what to do. Generally Modernizr.load is used to load polyfills so you should read this: http://www.modernizr.com/docs/#load

Modernizr 需要测试来决定要做什么。通常 Modernizr.load 用于加载 polyfill,因此您应该阅读以下内容:http: //www.modernizr.com/docs/#load