Here you provide three types of jquery instance code for dynamically loading Javascript. Because jquery is convenient for users, you only need one sentence to use jquery to dynamically load files $. getScript (\ "test. js \ "); then OK.
<! -- Three types of jquery instance code for dynamic loading of js are provided here. Because jquery is convenient for users, you only need one sentence to use jquery to dynamically load files $. getscript ("test. js "); then 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 methods </title>
<Script language = "webpage effect">
$. 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 );
}
// Simple enough! If you want to concentrate on the following, you can even use a single line of code:
// Method 3
$ ("<Scri" + "pt>" + "</scr" + "ipt> "). attr ({src: file, type: 'text/javascript ', id: 'load '}). appendto ($ ('head '). remove ('# loadscript '));
</Script>
</Head>
<Body>
</Body>
</Html>