<SCRIPT LANGUAGE=javascript> function addRow_withInsert(){
var row=document.getElementById("t1").insertRow( document.getElementById("t1").rows.length); var rowCount =document.getElementById("t1").rows.length; var countCell=document.getElementById("t1").rows.item(0).cells.length;
for(var i=0;i<countCell;i++){
if(rowCount!=2)
say("Detail"+(rowCount-1)+(i+1));
var cell=row.insertCell(i);
cell.innerHTML = '<input style="border-width:0px;width:100%;float:left" id="'+"Detail"+rowCount+(i+1)+'" type="text" value="'+"Detail"+rowCount+(i+1)+'"/>'
cell.id = "Detail"+rowCount+(i+1);
cell.name = "Detail"+rowCount+(i+1);
}
}
function say(id){
alert(id);
var aaa = document.getElementById(id);
document.getElementById("tdiv").innerHTML = aaa.value;
alert(aaa);
alert(aaa.value);
}
</SCRIPT>
<table width="500" border="1" align="center" cellspacing="0" bordercolor="#000000" id="t1">
<tr align="center">
<td><input style="border-width:0px;width:100%;float:left" name="sssss" type="text"/></td>
<td>删除</td> </tr>
</table>
<button class="button" onClick="addRow_withInsert()">添加一行</button>
<div id="tdiv"></div>
var row=document.getElementById("t1").insertRow( document.getElementById("t1").rows.length); var rowCount =document.getElementById("t1").rows.length; var countCell=document.getElementById("t1").rows.item(0).cells.length;
for(var i=0;i<countCell;i++){
if(rowCount!=2)
say("Detail"+(rowCount-1)+(i+1));
var cell=row.insertCell(i);
cell.innerHTML = '<input style="border-width:0px;width:100%;float:left" id="'+"Detail"+rowCount+(i+1)+'" type="text" value="'+"Detail"+rowCount+(i+1)+'"/>'
cell.id = "Detail"+rowCount+(i+1);
cell.name = "Detail"+rowCount+(i+1);
}
}
function say(id){
alert(id);
var aaa = document.getElementById(id);
document.getElementById("tdiv").innerHTML = aaa.value;
alert(aaa);
alert(aaa.value);
}
</SCRIPT>
<table width="500" border="1" align="center" cellspacing="0" bordercolor="#000000" id="t1">
<tr align="center">
<td><input style="border-width:0px;width:100%;float:left" name="sssss" type="text"/></td>
<td>删除</td> </tr>
</table>
<button class="button" onClick="addRow_withInsert()">添加一行</button>
<div id="tdiv"></div>
alert(aaa.value); 没值?
var row=document.getElementById("<%=t1.ClientID%>").insertRow( document.getElementById("<%=t1.ClientID%>").rows.length);参考网址:http://blog.csdn.net/sire168/archive/2010/06/22/5686041.aspx
document.getElementById("tdiv").innerHTML = aaa.innerHTML;
cell.id = "Detail" + rowCount + (i + 1);TD的ID跟input的ID一样
见W3C HTML401标准:
http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
其中说, This name must be unique in a document. 在文档中只能是独有的。因此,在使用document.getElementById()时取到的应该是td ,而不是input