20
2017-Sep
[javascript] js, css 파일 동적 로딩
작성자:
Blonix
IP ADRESS: *.64.228.3 조회 수: 1898
출처 :: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | function loadjscssfile(filename, filetype){ if (filetype=="js"){ //if filename is a external JavaScript file var fileref=document.createElement('script') fileref.setAttribute("type","text/javascript") fileref.setAttribute("src", filename) } else if (filetype=="css"){ //if filename is an external CSS file var fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet") fileref.setAttribute("type", "text/css") fileref.setAttribute("href", filename) } if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref)}loadjscssfile("myscript.js", "js") //dynamically load and add this .js fileloadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript fileloadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file |