<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 4 年前。
标签 javascript html css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 4 年前。
我该如何解决这个问题?
window.onload=function setup(){
createCanvas(200,200);
}
window.onload=function draw (){
background(55);
}
我在 html 页面中包含了 javascript 文件 当我运行 html 页面时不显示我的 Canvas 是否存在语法错误?
最佳答案
您不能有两个 window.onload
函数。每次您分配此属性时,它都会替换前一个。当页面加载时,只会调用最后一个。
您可以将这些功能合二为一:
window.onload = function() {
createCanvas(200,200);
background(55);
};
或者您可以使用addEventListener
添加多个事件监听器。
window.addEventListener("load", function() {
createCanvas(200, 200);
});
window.addEventListener("load", function() {
background(55);
});
关于javascript - 为什么我的函数没有显示在 html 页面中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53092669/