首页 > 代码库 > 动态加载JS

动态加载JS

res/js/modules/s01.js

alert("动态加载JS成功!"); 

 

形式1:

<script src="http://www.mamicode.com/layui-v1.0.9_rls/layui.js"></script>
<script>
    layui.use("res/js/modules/s01");
</script>

 

形式2:

<script src="http://www.mamicode.com/layui-v1.0.9_rls/layui.js"></script>
<script>
    layui.config({
        base : "res/js/modules/"
    }).use("s01");
</script>

 

形式3:

<script src="http://www.mamicode.com/layui-v1.0.9_rls/layui.js"></script>
<script>
    layui.config({
        base : "res/js/modules"
    }).use("/s01");
</script>

 

动态加载JS