Created
December 3, 2015 16:02
-
-
Save tranquangchau/8f4eeff95ebf3d1e7445 to your computer and use it in GitHub Desktop.
same ajax in local file html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<script type="text/javascript" src="test.js"></script> | |
<a href="javascript:loadjscssfile('myscript.js','js')">Load "myscript.js"</a> | |
<a href="javascript:loadjscssfile('mystyle.css','css')">Load "mystyle.css"</a> | |
<div class="demotable" style="background:red;">fsa</div> | |
<a href="javascript:test()">function test</a> | |
<div id="content"></div> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var petname="Spotty" | |
alert("Pet Name: " + petname) | |
function test(){ | |
alert("213"); | |
var div = document.createElement('div'); | |
//div.className = 'row'; | |
div.innerHTML='<ul> \ | |
<li>Coffee</li> <li>Tea</li> <li>Milk</li></ul>'; | |
document.getElementById('content').appendChild(div); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#demotable { | |
background:yellow; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file | |
//loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment