Home  >  Article  >  Web Front-end  >  Detailed explanation of the steps to load and remove js and css files

Detailed explanation of the steps to load and remove js and css files

php中世界最好的语言
php中世界最好的语言Original
2018-05-04 09:13:351818browse

This time I will bring you a detailed explanation of the steps to load and remove js and css files. What are the precautions and the following are practical cases. Let’s take a look at them together.

 

Usage example

loadjscssfile("myscript.js","js")
loadjscssfile("javascript.PHP","js")
loadjscssfile("mystyle.css","css")

//移动已经加载过的js/css
function removejscssfile(filename,filetype){
vartargetelement=(filetype=="js")? "script" :(filetype=="css")? "link" : "none"
var targetattr=(filetype=="js")?"src" : (filetype=="css")? "href" :"none"
varallsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0;i--){
if (allsuspects[i] &&allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
 allsuspects[i].parentNode.removeChild(allsuspects[i])
}
}

Usage example:

removejscssfile("somescript.js","js")
removejscssfile("somestyle.css","css")

I believe you have mastered the method after reading the case in this article. For more exciting things, please pay attention to php Other related articles on the Chinese website!

Recommended reading:

Summary of vue data transfer methods

vue storejs instructions for obtaining data

The above is the detailed content of Detailed explanation of the steps to load and remove js and css files. For more information, please follow other related articles on the PHP Chinese website!

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