这样写为什么不能动态增加一行?我应该怎样修改
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>
var newCell=Rows(newRow.rowIndex).insertCell(Cells.length);
改成
var newCell=Rows[newRow.rowIndex].insertCell(Cells.length); //javascript中数组是用[],不是()
改成
var newCell=Rows[newRow.rowIndex].insertCell(Cells.length); //javascript中数组是用[],不是()
还是不行,alert("过去"); 那里就无法执行
谢谢您,大神,你解救了被script捆绑的无知人类 TT
但是问题又来了,只要在tbody之前加上
http://www.jb51.net/article/73.htm
http://www.360doc.com/content/13/1106/22/7669533_327271586.shtml