This time I will bring you jquery a detailed explanation of dynamically loading js files. What are the precautions for jquery to dynamically load js files? The following is a practical case, let’s take a look.
$.extend({ include Path: '', include: function(file) { var files = typeof file == "string" ? [file]:file; for (var i = 0; i < files.length; i++) { var name = files[i].replace(/^\s|\s$/g, ""); var att = name.split('.'); var ext = att[att.length - 1].toLowerCase(); var isCSS = ext == "css"; var tag = isCSS ? "link" : "script"; var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language=' javascript ' type='text/javascript' "; var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'"; if ($(tag + "[" + link + "]").length == 0) $("body").append("<" + tag + attr + link + "></" + tag + ">"); } } }); //使用方法 $.includePath = '../js/Exam'; $.include(['/AddQuestion.js']);
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How jQuery reads the content of XML files
JQuery AJAX implementation file download
The above is the detailed content of Detailed explanation of jquery dynamically loading js files. For more information, please follow other related articles on the PHP Chinese website!