js动态加载元素

js动态加载元素

问题描述:

[code="java"]



function d(){ var button = document.frames["a"].document.createElement("button"); var text = document.frames["a"].document.createTextNode("ddd"); button.appendChild(text); document.frames["a"].document.appendChild(button); }

[/code]

createElement("button");

为什么把button改成createElement("p");就不能显示

input 对象不支持appendChild函数肯定直接报错。当docuemnt.appendChild能添加

document.frames["a"].document.body.appendChild(button);

应该是添加到body里面而不是document

不对!
1.0 首先 P 标签是支持 支持appendChild (查文档了!)
2.0
[code="java"] function d(){

var button = document.frames["a"].document.createElement("p");

var text = document.frames["a"].document.createTextNode("ddd");

      button.appendChild(text);  
       alert(0);
      [color=red]document.frames["a"].document.appendChild(button);    [/color]       alert(0);

} [/code]

红色部分是正常执行的!

可能需要加些必要的属性才会显示吧! 试试看

p标签不支持吧。一般都是添加到body里面的。

[quote]恩,确实可以。但是button为什么不要加也能显示? [/quote]

加了 body 估计button 都出不来了!

[quote] var button = document.frames["a"].document.body.createElement("button"); [/quote]

能通过?
我本地编辑器有问题?