Dynamic loading of jquery libraries

  • 2020-03-30 01:43:27
  • OfStack

Sometimes we may not be on the web. Script SRC ="jquery.min.js" to load the jquery library, maybe after the user clicks a button, to load the jquery library. I don't have to tell you, save bandwidth, improve access speed, because the user may not click this button, also do not need Jquery. So how do you load the Jquery library dynamically? You can print it out with document.write, you can print it out with Ajax, you can print it out in the following way:

<!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" >  
    <title> Dynamic loading Jquery Library, no need to create Ajax The request. in  a  the  href  Write one or more pieces of code in the property </title>  
    <style type="text/css">  
        #message { margin: 20px 10px; color:Green; }  
    <script language="javascript" type="text/javascript">  
        function AjaxLoadJquerylibrary()  
            var d = document, s = d.getElementById('firebug-lite');  
            if (s != null)  
            s = d.createElement('script');  
            s.type = 'text/javascript';  
            s.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js';  
            document.getElementById("content").style.display = "block";  
    <input type="button" value=" Dynamic import Jquery" onclick="AjaxLoadJquerylibrary();" /><br />  
<div id="message">  

 <div id="content">  
     Please enter your name: <input type="text" value="" id="txtUserName" /><br />  
    <a href="javascript:(function(){ var username = $('#txtUserName').val(); alert(username); })();void(0);">Jquery Get the name </a>  

Related articles: