This time I will show you how to dynamically operate js/css files, and what are the precautions for dynamically operating js/css files. The following is a practical case, let's take a look.
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 information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How to operate vue code specification detection
##mint-ui makes pull-down refresh on the mobile phone Pull-up loading
The above is the detailed content of How to dynamically operate js/css files. For more information, please follow other related articles on the PHP Chinese website!