Sometimes, we may not <SCRIPT src = "jquery. Min. js" in the webpage to load the jquery library. Users may only load the jquery library after clicking a button. I don't need to talk about the benefits, saving bandwidth and improving access speed.
Because the user may not click this button, jquery is not required. So how to dynamically load the jquery library? Generally, you can print it out using document. Write, Ajax, or the following
Formula:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <title> dynamically load the jquery library, you do not need to create an Ajax request. Write one or more <SPAN class = 'wp _ keywordlink'> Code </span> </title> <br/> <style type = "text/ CSS "> <br/> # message {margin: 20px 10px; color: green ;} <br/> </style> <br/> <script language = "JavaScript" type = "text/JavaScript"> <br/> function ajaxloadjquerylibrary () <br/> {<br/> var d = Document, S = D. getelementbyid ('firebug-lite '); <br/> If (s! = NULL) <br/> return; <br/> S = D. createelement ('script'); <br/> S. type = 'text/JavaScript '; <br/> S. src = 'HTTP: // ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js'; <br/> D. body. appendchild (s); <br/> document. getelementbyid ("content "). style. display = "Block "; <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body> <br/> <div> <br/> <input type = "button" value = "dynamically import jquery" onclick = "ajaxloadjquerylibrary (); "/> <br/> </div> <br/> <Div id =" message "> </P> <p> </div> <br /> <Div id = "content"> <br/> enter your name: <input type = "text" value = "" id = "txtusername"/> <br/> <a href = "javascript :( function () {var username = $ ('# txtusername '). val (); alert (username) ;}) (); void (0 ); "> jquery obtains the name </a> <br/> </div> <br/> </body> <br/> </ptml>