我和LABjs有点问题。我加载了所有的脚本,但当我在IE中使用它时,它完全崩溃了。
$LAB
.script('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js').wait()
.script('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js')如果我添加一个条件语句
<!--[if IE ]>
<script type="text/javascript" src="somescript.js"></script>
<![endif]-->这将会失败。我如何将其包含到LABjs中?
谢谢。
发布于 2012-08-26 00:31:49
我首先强烈地说,你不应该再只做IE脚本了。但是,如果你真的必须这样做,并且在你因为那次糟糕的练习而数次拍打自己的手腕之后……
(function(){
// From: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
var ie_version=(function(){var c,a=3,b=document.createElement('div'),d=b.getElementsByTagName('i');while(b.innerHTML='<!--[if gt IE '+(++a)+']><i></i><![endif]-->',d[0]);return a>4?a:c})();
$LAB.setOptions({AlwaysPreserveOrder:true})
.script('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js')
.script('https:///ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js')
.script(ie_version ? 'somescript.js' : '')
})();ie_version代码片段来自:http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/,它使用动态创建的IE条件注释来确定IE版本。
注意:根据您发布的内容,我假设"somescript.js“需要严格在jquery和jquery-ui脚本之后执行。如果不是这样,您可以根据需要将它放在$LAB链中的不同位置,并且可以去掉setOptions({AlwaysPreserveOrder:true}),只在需要/需要的时候在链中使用wait()。
https://stackoverflow.com/questions/12114456
复制相似问题