我想弄清楚为什么会这样:
<script src="js/head.js"></script>
<script>head.js(<import-several-libraries-here>);</script>
<script src="code.jquery.com/jquery-1.8.3.js"></script>
<script src="code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
var j183 = $.noConflict(true);
</script>但这些并不是:
<script src="js/head.js"></script>
<script>
head.js(<import-several-libraries-here>);
head.js("http://code.jquery.com/jquery-1.8.3.js");
head.js("http://code.jquery.com/ui/1.9.2/jquery-ui.js");
var j183 = $.noConflict(true);
</script>和
<script src="js/head.js"></script>
<script>
head.js(<import-several-libraries-here>);
head.js("http://code.jquery.com/jquery-1.8.3.js");
head.js("http://code.jquery.com/ui/1.9.2/jquery-ui.js");
</script>
<script>
var j183 = $.noConflict(true);
</script>我读过这篇文章,尝试过各种变体,但都没有用:
更新
我尝试了一个建议的答案:
head.js("http://code.jquery.com/ui/1.9.2/jquery-ui.js");
head.js("http://code.jquery.com/jquery-1.8.3.js", function() {
var j183 = $.noConflict(true);
});但没起作用。
发布于 2013-01-12 00:25:45
根据http://headjs.com/
也许您应该尝试这样的方法,它将加载两个jQuery库,然后调用匿名函数,该函数将jQuery库重新分配给全局变量以供以后使用。
<script src="js/head.js"></script>
<script>
head.js(<import-several-libraries-here>);
head.js("http://code.jquery.com/jquery-1.8.3.js",
"http://code.jquery.com/ui/1.9.2/jquery-ui.js", function() {
window.j183 = $.noConflict(true);
head.js(<import-several-libraries-here>, function(){
init();
}); //that depend on j183
});
function init(){
var $ = window.j183;
$('body').each(function(){
//do something
});
j183('body').each(function(){
//do something else
});
}
</script>更新:,展示如何在库中插入。
发布于 2013-01-12 00:12:48
您需要在回调中通过head.js执行任何依赖项加载的代码:
head.js("/path/to/jquery.js", function() {
var j183 = $.noConflict(true);
});https://stackoverflow.com/questions/14288586
复制相似问题