功能说明
在项目中要实现HTML中table列 的新增和删除
<script language="javaScript">
var cGetRow=-99999;
var index=0;
function DelRow(o)
{
//删除一行
cGetRow=o.parentNode.parentNode.rowIndex;
if(cGetRow==-99999)
alert("系统提示:没有选中行号!");
else
tab1.deleteRow(cGetRow);
}
function AddRow()
{
//添加一行
var newTr = tab1.insertRow();
//添加4列
var newTd0 = newTr.insertCell();
var newTd1 = newTr.insertCell();
var newTd2=newTr.insertCell();
var newTd3=newTr.insertCell();
//设置列内容和属性
newTd0.innerHTML = '';
newTd1.innerHTML= '<select name="List1" οnchange="change(this)"><option value="1">文本</option> <option value="2">图片</option> </select>';
newTd2.innerHTML='<textarea name="List2" cols="100" rows="25"></textarea> <input name="uploadFile(index++)" type="file" size="40"/>';
newTd3.innerHTML='<input type="button" value="删除" name="B1" οnclick="javascript:DelRow(this)"/>';
}
</script>
<input name="add" type="button" οnclick="AddRow()" value="新增" />