我想在加载时调用一个函数,但它不起作用 它在iframe中如果有所作为。 别介意html; 提前谢谢你。
var canvas = document.getElementById('my_canvas');
var ctx = canvas.getContext('2d');
canvas.width = 320;
canvas.height = 240;
var back = new Image();
var reg = new Image();
var spicy = new Image();
var nosauce = new Image();
var setup1 = setup();
function setup(){
back.src = "selectback.png";
reg.src = "reg.png";
spicy.src = "spicy.png";
nosauce.src = "sauce.png";
back.onload = function(){
ctx.drawImage(back, 0, 0, 321, 241);
};
}
function back(){
var test = new Image();
test.onload = function() {
ctx.drawImage(test, 0, 0, 300, 300);
};
}
window.onload = function () { setup(); }
答案 0 :(得分:1)
这样做:
document.getElementById('YourIframeId').onload = function() {
setup();
// put your awesome code here
};