我有按钮的html页面:文件撰写擦除按钮
<INPUT TYPE=BUTTON VALUE="b1" onclick="init1()" >
INIT1:
document.innerHTML = "<object type='application/x-app' id='plugin' width='0' height='0' > </object>"
当我按下B1它删除的页面,它只是空白按钮。 我在做什么错? 10xs, Nir
我有按钮的html页面:文件撰写擦除按钮
<INPUT TYPE=BUTTON VALUE="b1" onclick="init1()" >
INIT1:
document.innerHTML = "<object type='application/x-app' id='plugin' width='0' height='0' > </object>"
当我按下B1它删除的页面,它只是空白按钮。 我在做什么错? 10xs, Nir
使用appendChild
而不是取代(=
)。你的按钮不会被擦除。
var object = document.createElement("object");
object.innerHTML = "<object...";
document.body.appendChild(object);
当然,它会擦除页面。当您修改完整文档的.innerHTML
并将其替换为其他内容时,会发生这种情况。
但是,如果您想将该标签附加到文档上,那就是另一回事了。我建议以下做这样的:
var your_element = document.createElement('object');
your_element.type = 'application/x-app';
your_element.id = 'plugin'
your_element.width = 0;
your_element.height = 0;
document.body.appendChild(your_element);
您需要住址在代码中适当的锚(地方)(DOM树)。
试试这个:对身体
var my_anchor = document.getElementById('element_in_DOM');
my_anhor.innerHTML = "<object type='application/x-app' id='plugin' width='0' height='0' > </object>"
因为您更换与该对象标记... – sachleen
'document.write'整个文档的HTML和分配到'document.innerHTML'是两种完全不同的操作DOM的方法。 – troelskn