The example in this article describes the method of jQuery parsing XML files and dynamically adding js files. Share it with everyone for your reference. The specific implementation method is as follows:
$(function(){ $.ajax({ url: 'js/config/jsConfig.xml', dataType: 'xml', success: function(data){ $(data).find("moduleName").each(function(i,obj) { var field = $(this); var funcName = field.attr("name"); for(var i = 0;i < field.find("func").size();i++){ var func = field.find("func:eq(" + i + ")").text(); var src = '<script type="text/javascript" src=\"' + func + ".js\"></script>"; $("body").append(src); } }); } }); })
<?xml version="1.0" encoding="UTF-8"?> <module> <moduleName name = "管理"> <func>js/module/testXml</func> <func>js/module/device</func> </moduleName> </module>
I hope this article will be helpful to everyone’s jQuery programming.