这样写为什么不能动态增加一行?我应该怎样修改
function insertRows(){ var tempRow=0; var tbl=document.getElementById("dictTbl"); tempRow=tbl.rows.length; //获取当前table的行数 var Rows=tbl.rows;//类似数组的Rows var newRow=tbl.insertRow(tbl.rows.length);//插入新的一行 var Cells=newRow.cells;//类似数组的Cells for (i=0;i<4;i++)//每行的3列数据 { alert("进入"); var newCell=Rows(newRow.rowIndex).insertCell(Cells.length); alert("过去"); newCell.align="center"; switch (i) { case 0 : newCell.innerHTML="<td align=\"center\"><input type=\"checkbox\"/></td>";break; case 1 : newCell.innerHTML="<td align=\"center\" width=\"120px\">" + "</td>";break; case 2 : newCell.innerHTML="<td align=\"center\"\><input id=\"classifyName\" name=\"classifyName\" type=\"text\" size=\"50\" maxlength=\"25\"/></td>";break; case 3 : newCell.innerHTML="<td width=\"400px\"></td>";break; } } }
...
删除 添加选项
<s:form name="Form1" id="Form1" method="post">
<table cellpadding="0" cellspacing="0" border="0" id="table1" class="stdtable stdtablecb">
<colgroup>
<col class="con0" style="width: 4%"/>
<col class="con1" />
<col class="con0" />
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head0"><input type="checkbox" class="checkall"/></th>
<th class="head1">分类级别</th>
<th class="head0">分类名称</th>
<th class="head1">继承父分类</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="head0"><input type="checkbox" class="checkall"/></th>
<th class="head1">分类级别</th>
<th class="head0">分类名称</th>
<th class="head1">继承父分类</th>
</tr>
</tfoot>
<tbody id="dictTbl">
<s:if test="#request.classifyList!=null && #request.classifyList.size()>0">
<s:iterator value="%{#request.classifyList}" var="class">
<tr>
<td align="center"><input type="checkbox"/></td>
<td align="center" width="120px"><s:property value="%{#class.rank}"/></td>
<td align="center">
<input id="classifyName" name="classifyName" type="text" value="<s:property value="%{#class.classifyName}"/>" size="50" maxlength="25"/>
</td>
<td width="400px"><s:property value="%{#class.inherit}"/></td>
</tr>
</s:iterator>
</s:if>
</tbody>
</table>
<table style="margin-top: 20px;float: right;">
<tr>
<td>
<button class="radius3" id="savebutton" style="width: 70px;" onclick="">保存</button>
</td>
</tr>
</table>
<scritp>
function insertRows(){
var tempRow=0;
var tbl=document.getElementById("dictTbl");
tempRow=tbl.rows.length; //获取当前table的行数
var Rows=tbl.rows;//类似数组的Rows
var newRow=tbl.insertRow(tbl.rows.length);//插入新的一行
var Cells=newRow.cells;//类似数组的Cells
for (i=0;i<4;i++){//每行的3列数据 { alert("进入");
var newCell=Rows[newRow.rowIndex].insertCell(Cells.length);
alert("过去"); newCell.align="center";
switch (i) {
case 0 :
newCell.innerHTML="<td align=\"center\"><input type=\"checkbox\"/></td>";break;
case 1 :
newCell.innerHTML="<td align=\"center\" width=\"120px\">" + "</td>";break;
case 2 : newCell.innerHTML="<td align=\"center\"\><input id=\"classifyName\" name=\"classifyName\" type=\"text\" size=\"50\" maxlength=\"25\"/></td>";break;
case 3 : newCell.innerHTML="<td width=\"400px\"></td>";break;
}
}
}
</script>
<body>
<table>
<tbody id='dictTbl'>
</tbody>
</table>
</body>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。