首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js 添加行解决方法

2013-03-12 
js 添加行我想按下“添加选项”按钮以后,在问题一行的下面添加选项,不过没有办法运行,报错Uncaught TypeErro

js 添加行
我想按下“添加选项”按钮以后,在问题一行的下面添加选项,不过没有办法运行,报错Uncaught TypeError: Object #<HTMLInputElement> has no method 'insertCell' ,我的代码:


function $(id)
{
return document.getElementById(id);
}

function addRow(){
var tableObj = $("testTable");
var rowObj = tableObj.insertRow(-1);
rowObj.setAttribute("id","newRow");
var cellObj1 = rowObj.insertCell(-1);
var cellObj2 = rowObj.insertCell(-1);

cellObj1.innerHTML = '问&nbsp;&nbsp;&nbsp;&nbsp;题:<input type="text" id="question" value=""/>';
cellObj2.innerHTML ='<input type="button" value="添加选项" onclick="addOption()"/>'+ '<input type="button" value="删除问题" onclick="delRow(this)"/>';

}

function addOption(){
var questionObj=$("question");
var optionObj=questionObj.rowIndex;
questionObj.setAttribute("id","option");
var oObj1=questionObj.insertCell(-1);
var oObj2=questionObj.insertCell(-1);

oObj1.innerHTML ='选项<input type="text" id="oid"/><input type="text" value="" id="content" />';
oObj2.innerHTML ='<input type="button" value="添加" onclick="addOption()"/>'+ '<input type="button" value="删除" onclick="delRow(this)"/>';
}
javascript 添加行
[解决办法]
getElementsByTagName("button") 应该为getElementsByTagName("input")
[解决办法]
用createElement

热点排行