如何在表格单元格中插入输入字段?

Cra*_*ayl 4 javascript

对于noob问题很抱歉:我想创建一个包含输入字段的表,如果需要,可以添加新字段.但我无法弄清楚如何在另一个输入字段已经存在的单元格中添加另一个输入字段.

我的代码是:

var par=obj.parentNode;
while(par.nodeName.toLowerCase()!='tr')
{ par=par.parentNode; }
// this gives me the index of the row.. works fine.

cell1=document.getElementById('avz_tabelle').rows[par.rowIndex].cells;
// this puts the content of the cells into the array "cell1"

var feld = cell1[1].createElement("input"); 
feld.setAttribute("name","avz_keywords" + avz_array + "[]"); 
feld.setAttribute("onblur","");
feld.setAttribute("type","text"); 
feld.setAttribute("size","30"); 
// Now I create a input element
// And now comes the problem:

cell1[1].appendChild(feld); // --> doesn't work
Run Code Online (Sandbox Code Playgroud)

有人对我提出建议吗?我有了一个没有桌子工作的想法,理论上这可以用我的方式.但这不会令人满意:/

Mic*_*ski 6

如果您查看调试控制台,您应该会看到类似的内容

TypeError: Object #<HTMLDivElement> has no method 'createElement'
Run Code Online (Sandbox Code Playgroud)

而不是创建元素cell1[1],使用document.createElement()

 var feld = document.createElement("input");
Run Code Online (Sandbox Code Playgroud)