// 动态添加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();
-------------------
-
var script = document.createElement('script');
-
script.type = 'text/jacascript';
-
script.src = 'url'; //填自己的js路径
-
$('body').append(script);
-