Three kinds of dynamic loading js jquery instance code with js removal methods

  • 2020-03-30 02:46:55
  • OfStack

 
!--  Here are three dynamic loads for you js the jquery Instance code oh, because jquery Is for the user to provide convenience, so use jquery Dynamically loading a file is just one sentence $.getscript("test.js"); it ok .  
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 

<title>jquery  Dynamic loading js Three methods </title> 
<script language=" Web page special effects "> 
$.getscript("test.js"); 

//Method 2

function loadjs(file){ 
var head = $('head').remove('#loadscript'); 
$("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto(head); 
} 

//Easy enough! You can even do it all in one line of code if you condense the following:
//Methods three

$("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto($('head').remove('#loadscript')); 

</script> 

</head> 

<body> 
</body> 
</html> 

Jquery remove js
 
$("script[src='../static/js/cpu_memory.js']").remove(); 
$("script[src='../static/js/wan_flow.js']").remove(); 

Related articles: