让Js顺序执行且回调之

<script src="aaa"></script>

<script type="aaasdf" id="asdf">

    function aaa()

    {

    }

</script>



<script>

    var scripts = [];

    $('script[src!=""]').each(function () {

        scripts.push($(this).attr('src'));

    });



    function load(x, y) {

        if (x > scripts.length) {

            y();

            return;

        }

        var script = scripts[x];

        loadScript(script, load(x++, y));

    }



    load(0, callback);



    var jsArray = {};

    function loadScript(a, b) {

        if (jsArray[a]) b && b();

        else {

            jsArray[a] = !0;

            var c = document.getElementsByTagName("body")[0],

                d = document.createElement("script");

            d.type = "text/javascript", d.src = a, d.onload = b, c.appendChild(d);

        }

    }

</script>

你可能感兴趣的:(js)