gpt4 book ai didi

javascript - 如何确保 "document.body.appendChild(flash_object)"在下一行之前加载?

转载 作者:行者123 更新时间:2023-11-28 05:40:26 24 4
gpt4 key购买 nike

有什么方法可以确保在调用 foo() 之前加载 Flash 进程吗?

window.onload = function (){
document.body.appendChild(CreateFlashObject("flash_obj"));
foo();
}
function CreateFlashObject(objectName){
var obj = document.createElement("object");
obj.setAttribute("id", objectName);
obj.setAttribute("type", "application/x-shockwave-flash");
}
function foo(){
//doing something with the flash_obj
}

最佳答案

您可以将新创建​​的 html 元素传递给 foo 函数。您甚至不需要加载它即可对其进行更改。

window.onload = function (){
var obj = CreateObject("foo_obj1");
var obj2 = CreateObject("foo_obj2");
document.body.appendChild(obj);
boo();
foo(obj2);
document.body.appendChild(obj2);
console.log(obj,obj2);
}
function CreateObject(objectName){
var obj = document.createElement("object");
obj.setAttribute("id", objectName);
return obj;
}
function foo(obj){
obj.width = 400;
obj.height = 400;
}
function boo() {
var obj = document.getElementById("foo_obj1");
obj.width = 200;
obj.height = 200;
}

关于javascript - 如何确保 "document.body.appendChild(flash_object)"在下一行之前加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com