在调用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
}
答案 0 :(得分:0)
您可以将新创建的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;
}