我一直在使用 javascript 构建脚本标记。当我使用此脚本加载其他三个脚本时,该脚本未按顺序加载。我希望首先加载 jquery.min.js。所以我用它作为第一个参数。但一开始它并没有被加载。所以我陷入了引用错误。谁能告诉我我在这段代码中犯了什么错误。我的代码在这里
<script type="text/javascript">
(function (a, b, c) {
var g = document.createElement('script');
g.type = 'text/javascript';
g.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://') + a;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(g, s);
var g = document.createElement('script');
g.type = 'text/javascript';
g.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + b;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(g, s);
var g = document.createElement('script');
g.type = 'text/javascript';
g.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + c;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(g, s);
})('ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', '.example.com/js/script.js', '.example.com/js/form.js');
</script>
最佳答案
使用 require.js 进行动态脚本加载。它会起作用。另外,尝试在网站上方使用 jquery.js 而不是使用脚本生成。
关于javascript - 脚本未按顺序加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18350051/