Home >Web Front-end >JS Tutorial >jQuery.getScript loads the code of JS in the same domain_jquery

jQuery.getScript loads the code of JS in the same domain_jquery

WBOY
WBOYOriginal
2016-05-16 17:56:16980browse

Solution, use the following method to load js:

Copy the code The code is as follows:

var loadScript = function(url, callback, charset){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
if(charset){
script.charset = charset;
}
script.src = url;
if(!callback){
return;
}
script.onload = script.onreadystatechange = function(){
if(!this.readyState || this.readyState==='loaded' || this.readyState==='complete'){
callback();
}
};
head.appendChild(script);
};
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