Home >Web Front-end >JS Tutorial >How jQuery parses XML files and dynamically adds js files_jquery

How jQuery parses XML files and dynamically adds js files_jquery

WBOY
WBOYOriginal
2016-05-16 15:57:071154browse

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);
    }
   });
  }
 });
})
<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn