Asynchronously loading and executing a JS file using the Getscript () method
Use the getScript() method to asynchronously request and execute a file in JavaScript format on the server, whose invocation format is as follows:
jQuery.getScript(url,[callback])Or$.getScript(url,[callback])
The parameter URL is the server request address, and the optional callback parameter is the callback function that executes after the request succeeds.
1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<title> asynchronously loads and executes the JS file using the Getscript () method </title>5<script src= "Http://libs.baidu.com/jquery/1.9.0/jquery.js" type= "Text/javascript" ></script>6<style>7 #divtest8 {9 width:282px;Ten } One #divtest. Title A { - padding:8px; -background-Color:blue; the color: #fff; - height:23px; -line-height:23px; -font-size:15px; +font-Weight:bold; - } + ul A { at float: Left; - width:280px; - padding:5px 0px; - margin:0px; -font-size:14px; -list-style-Type:none; in } - ul Li to { + float: Left; - width:280px; the height:23px; *line-height:23px; $ padding:3px 8px;Panax Notoginseng } - . FL the { + float: Left; A } the . Fr + { - float: Right; $ } $</style> - - the<body> -<div id= "Divtest" >Wuyi<div class= "title" > the<span class= "FL" > My favorite Sport </span> -<span class= "FR" > Wu<input id= "btnshow" type= "button" value= "Load"/> -</span> About</div> $<ul></ul> -</div> - -<script type= "Text/javascript" > A$(function () { +$ ("#btnShow"). Bind ("click",function () { the var$ This= $( This); -$.getscript ("./sport.js",function(){ $$ This. attr ("Disabled", "true"); the }); the }) the }); the</script> -</body> inView Code1 vardata = [{2"Name": "Football"3 },{4"Name": "Basketball"5 },{6"Name": "Table tennis"7 },{8"Name": "Volleyball"9 }];Ten$.each (data,function(index,sport) { One$ ("ul"). Append ("<li>" +sport[' name ']+ "</li>"); A});View CodeAsynchronously loading and executing a JS file using the Getscript () method