Home > Web Front-end > JS Tutorial > body text

How jQuery parses XML files and dynamically adds js files_jquery

WBOY
Release: 2016-05-16 15:57:07
Original
1125 people have browsed it

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);
    }
   });
  }
 });
})
Copy after login
<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<module>
 <moduleName name = "管理">
 <func>js/module/testXml</func>
 <func>js/module/device</func>
 </moduleName>
</module>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template