我在我的项目中使用 Require JS,它加载 jQuery 和其他一些与整个网站和所有浏览器相关的 JavaScript 文件。
但是,我需要在 Internet Explorer 7 和 8 上使用一些条件 jQuery,我尝试将其放在页面的头部,但脚本似乎无法找到 jQuery,我认为这是因为它是在 jQuery 之前加载。
<script data-main="/@ViewBag.ScriptsFolder/main" src="/scripts/require.js" type="text/javascript"></script>
<!--[if (gte IE 6)&(lte IE 8)]>
<script type="text/javascript" src="/Scripts/ie.js"></script>
<![endif]-->
有什么办法可以纠正这个问题吗?我也尝试以这种方式加载 Selectivizr,但由于同样的问题而无法正常工作。
Thanks
您可以在html
元素,然后检查它并加载现有的 IE 依赖项main
脚本。因此,文档的顶部将如下所示:
<!--[if lt IE 7]> <html class="ie lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="ie lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="ie lt-ie9"> <![endif]-->
<!--[if gt IE 8]> <html class="ie"> <![endif]-->
<html>
然后里面main.js
,你可以使用:
if ($('html.lt-ie9').size()) {
require(['/Scripts/ie'], function(ieScript) {
// ... do stuff
});
}
您无法使用您所描述的方法,因为 require.js 会查找单个data-main
属性来指定“入口点” - 任何后续调用require
应该在 JavaScript 中完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)