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

How to dynamically import js files and how to implement it_javascript skills

WBOY
Release: 2016-05-16 17:03:51
Original
1003 people have browsed it

When we want to dynamically import js files, we can use the following method

Copy the code The code is as follows:

var docFunc = {

/***************************************************** *************************
* purpose: Call the following dynamic loading script method load_script
************ *************************************************** **************/

loaddefJquery : function() {
//alert(ucapSession.hostPath ucapSession.appPath);

//ucapSession.appPath is the root directory
docFunc.load_script(ucapSession.appPath
"ftdxxglxt/js/jquery-1.8.1.min.js");
docFunc.load_script (ucapSession.appPath
"ftdxxglxt/js/jSuggest.js");
},

/***************************************************** ***************************
* purpose: dynamic loading script
****************** *************************************************** ***********/
load_script:function(url){
var x = new ActiveXObject("Msxml2.XMLHTTP");
x.open('GET', url, false);
x.send('');
eval(x.responseText);
var s = x.responseText.split(/n/);
var r = /^(?:function|var)s*([a-zA-Z_] )/i;
for (var i = 0; i < s.length; i )
{
var m = r.exec(s[i]);
if (m != null)
{
window[m[1]] = eval(m[1]);
}
}
}

}

in html page or jsp page calling method:
Copy code The code is as follows:

<script> <br> docFunc.loaddefJquery(); <br></script>
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