动态加载JS/CSS文件--改进版
//动态加载js、css内容,直接写入页面:动态添加js/CSS的内容在页面上:function loadScriptString(code){ var script = document.createElement("script"); script.type = "text/javascript"; try { script.appendChild(document.createTextNode(code)); } catch (ex){ script.text = code; // IE } document.body.appendChild(script);} function loadStyleString(css){ var style = document.createElement("style"); style.type = "text/css"; try{ style.appendChild(document.createTextNode(css)); } catch (ex){ style.styleSheet.cssText = css; //IE } var head = document.getElementsByTagName("head")[0]; head.appendChild(style);}Usage: loadScriptString('function sayHi(){alert("hi");}'); loadStyleString('body{background-color:red}');