1 | <html> |
---|
2 | <body> |
---|
3 | <a href="javascript:loadJQuery()">Load jQuery</a> |
---|
4 | |
---|
5 | <script type="text/javascript"> |
---|
6 | function loadJQuery() { |
---|
7 | var script = document.createElement('script'); |
---|
8 | script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'; |
---|
9 | var head = document.getElementsByTagName('head')[0]||document.body; |
---|
10 | var done = false; |
---|
11 | // Attach handlers for all browsers (taken from jQuery). |
---|
12 | script.onload = script.onreadystatechange = function() { |
---|
13 | if (!done && (!this.readyState || |
---|
14 | this.readyState === 'loaded' || |
---|
15 | this.readyState === 'complete')) { |
---|
16 | done = true; |
---|
17 | script.onload = script.onreadystatechange = null; |
---|
18 | |
---|
19 | alert('before ready: ' + $.isReady); |
---|
20 | $(document).ready(function() { |
---|
21 | alert('inside ready: ' + $.isReady); |
---|
22 | }); |
---|
23 | } |
---|
24 | }; |
---|
25 | |
---|
26 | head.appendChild(script); |
---|
27 | } |
---|
28 | </script> |
---|
29 | </body> |
---|
30 | </html> |
---|