从多个脚本标记中获取URL的数组作为字符串

时间:2016-08-18 09:12:49

标签: javascript

我需要编写一个javascript代码来将所有脚本url作为数组返回

var x='<script src="js/templates/templates.combined.js"></script><script src="js/anuj-ajaxService.js"></script><script src="js/anuj-algos.js"></script><script src="js/anuj-utils.js"></script><script src="js/anuj-scrolling.js"></script><script src="js/anuj-handlebarHelpers.js"></script><script src="js/anuj-global.js"></script><script src="modules/anuj-header/js/anuj-header.js"></script><script src="modules/anuj-menu/js/anuj-menu.js"></script><script src="modules/anuj-sections-nav/js/anuj-sections-nav.js"></script><script src="modules/anuj-section--action/js/anuj-section--action.js"></script><script src="modules/anuj-section--content/js/anuj-section--content.js"></script><script src="modules/anuj-carousel/js/anuj-carousel.js"></script><script src="modules/anuj-advisers/js/personalise.js"></script><script src="modules/anuj-advisers/js/anuj-advisers.js"></script><script src="modules/anuj-testimonials/js/anuj-testimonials.js"></script><script src="modules/anuj-section--lifestage/js/anuj-section--lifestage.js"></script><script src="modules/anuj-section--personalise/js/anuj-section--personalise-conversation.js"></script><script src="modules/anuj-search/js/anuj-search.js"></script><script src="modules/anuj-forms-docs/js/anuj-forms-docs.js"></script><script src="modules/anuj-thought-leadership/js/anuj-thought-leadership.js"></script><script src="modules/anuj-video/js/anuj-video.js"></script><script src="modules/anuj-sitemap/js/anuj-sitemap.js"></script><script src="modules/anuj-section--mjo/js/anuj-section--mjo.js"></script><script src="modules/anuj-section--mjo/js/anuj-section--mjo--validation.js"></script><script src="modules/anuj-section--mjo/js/anuj-section-mjo--insurance.js"></script><script src="modules/anuj-profile-overlay/js/anuj-profile-overlay.js"></script><script src="modules/anuj-sitemap/js/anuj-tabbed.js"></script>';

以上将返回

["js/templates/templates.combined.js","js/anuj-ajaxService.js","js/anuj-algos.js"...]等......

1 个答案:

答案 0 :(得分:0)

如果我正确地抓住你的问题,这应该可以胜任。

    <script>

        // this is pseudo-code

        function show_stats(json){
                  $("#holder").text("stuff from json")
                }

    $( document ).ready(function() {            
                $.ajax({
                  url: "https://myapp.mycompany.com",
                  dataType: "jsonp",
                  jsonpCallback: "show_stats"
                });
});

      </script>


        <p id="holder"></p>