試圖製作一個簡單的小部件。 步驟:javascript回調上下文問題
1)如果不是已經有 2加載的jQuery)回調函數
<html>
<head>
<script type="text/javascript">
function load(callback){
console.log('load');
if (typeof jQuery !== "function") {
var js = document.createElement("script");
var he = document.getElementsByTagName('head')[0];
js.type = "text/javascript";
js.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
he.appendChild(js);
js.addEventListener("load", function() {
callback();
});
}
else
{
callback();
}
}
load(function(){
chart();
})
function chart(){
$('#chart').html("id : "+Math.random());
}
// alert('This alert breaks!');
</script>
</head>
<body>
<div id="chart"></div>
</body>
</html>
代碼工作沒有警報。不能理解上下文問題
謝謝
在Chrome中適用於我:http://jsfiddle.net/Zwa7Q/ –
您的問題是什麼? –
在FF中適合我。 – juanpaco