我想嵌入并显示一个Flash文件。它适用于document.write,但是当我尝试使用AppendChild(文本)时,它不会显示Flash,而是显示纯文本。用什么DOM方法代替?document.write和DOM element.AppendChild之间的Javascript差异
<html>
<head>
<script>
function addText(text,elementId){
if (document.createTextNode){
var mytextNode=document.createTextNode(text)
document.getElementById(elementId).appendChild(mytextNode)
}
}
</script>
</head>
<body>
<div id="test">
</div>
<script>
addText("<embed height='100' width='100' type='application/x-shockwave-flash' allowscriptaccess='always' wmode='transparent' quality='high' swliveconnect='true' name='test' id='test' src='test.swf'>",'test');
</script>
</body></html>
您是不是想要使用'.innerHTML'? –
我想你想要document.createElement()来代替。 –
这可能有助于http://stackoverflow.com/questions/367214/document-write-vs-inserting-dom-nodes-preserve-form-information –