Last active
December 21, 2015 16:29
-
-
Save kfly8/6333777 to your computer and use it in GitHub Desktop.
ajaxでscript タグの入ったHTMLを読み込んだときに、scriptを読み込んでくれないのはどうして?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> | |
| </head> | |
| <body> | |
| hello!! | |
| <div id="hoge"></div> | |
| <script> | |
| $(document).ready(function() { | |
| $.get("./script.html", function(data) { | |
| $("#hoge").html(data); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| script load.. | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js"></script> | |
| <script> | |
| console.log(_); // defined? No!! not defined... | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| script load.. | |
| <script> | |
| document.open(); | |
| document.write("<script src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js'><\/script>"); | |
| document.close(); | |
| console.log(_); // _ is defined.. but script is written in head tag and "script loaded" and "hello!!" is deleted. | |
| </script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
script2.htmlで試した場合の挙動と比較すると、
headタグ内に書かないときちんとブロックして読み込んでくれない?