【jq】查看\增加]\删除是否有对应的js,css文件

RT


function loadjscssfile(filename, filetype){
    if (filetype=="js"){
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src",filename)
        }else if (filetype=="css"){
        var fileref=document.createElement("link")
        fileref.setAttribute("rel","stylesheet")
        fileref.setAttribute("type","text/css")
        fileref.setAttribute("href",filename)
        // console.log("输出当前添加的",filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

function removejscssfile(filename,filetype){
    var targetelement=(filetype=="js")? "script" :(filetype=="css")? "link" : "none"   
    var targetattr=(filetype=="js")?"src" : (filetype=="css")? "href" :"none"
    var allsuspects=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])
        }
		// console.log("输出",filename)
    }  
//检测页面js
function isInclude(filename,filetype){
    var targetelement=(filetype=="js")? "script" :(filetype=="css")? "link" : "none"   
    var targetattr=(filetype=="js")?"src" : (filetype=="css")? "href" :"none"
    var allsuspects=document.getElementsByTagName(targetelement)
	for(var i=0;i

 

资料来源:

https://www.cnblogs.com/wind-wang/p/11226821.html

你可能感兴趣的:(JQ,前端)