动态添加js  和 css_54-es9

// 动态添加js
function appendJQCDN(src) {
    var head = document.head || document.getElementsByTagName('head')[0];
    if(src.indexOf("js")== -1){ //css
        var style = document.createElement('style');
        style.setAttribute("rel", "stylesheet"); 
        style.setAttribute("href",src);
        head.appendChild(style);
    }else{
        var script = document.createElement('script');
        script.type = "text/javascript";
        script.setAttribute("src",src);
        head.appendChild(script);
    }
}

appendJQCDN("css/animate.css");
appendJQCDN("css/public.css");
appendJQCDN("js/jquery-3.5.0.min.js");
appendJQCDN("js/common.js");

 

 

function appendJQCDN(){
    var head = document.head || document.getElementsByTagName('head')[0];
    
    head += '<link rel="stylesheet" href="css/animate.css" />';
    head += '<link rel="stylesheet" href="css/public.css" />';
    head += '<link rel="stylesheet" href="css/style.css" />';
    head += '<script type="text/javascript" src="js/jquery-3.5.0.min.js"></script>';
    head += '<script type="text/javascript" src="js/common.js"></script>';
    
    document.getElementsByTagName('head')[0].innerHTML += head;
}
appendJQCDN();



-------------------

    1. var script = document.createElement('script');
    2.  
      script.type = 'text/jacascript';
    3.  
      script.src = 'url'; //填自己的js路径
    4.  
      $('body').append(script);