我正在动态添加github gist的脚本.如果我在页面加载之前将其添加到html,脚本将执行.但是如果我在加载后尝试将其添加到页面,它会将脚本添加到页面但不执行它.
以下是我将其添加到页面的方式
HTML
<div id="results"></div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$('#results').click(function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://gist.github.com/1265374.js?file=GetGists.js";
document.getElementById('results').appendChild(script);
console.log('script added');
});
Run Code Online (Sandbox Code Playgroud)
这是现场的例子