首先给 table 加 id =tblfor(i=0;i<tbl.rows.length;i++){
for(t=0;t<tbl.rows.(i).cells.length;t++)
alert("这是第"+i+"行第"+t+"列的值"+tbl.rows(i).cells(t).innerHTML)}
for(t=0;t<tbl.rows.(i).cells.length;t++)
alert("这是第"+i+"行第"+t+"列的值"+tbl.rows(i).cells(t).innerHTML)}
|tbody |最后以行 |最后一列 |里面的第一个对象--input有 dhtml 和 dom 两种方法 读取表格。前一种是dhtml ,后一种是 dom
....
<script>
function getValue(oTable){
var s=""
for(i=0;i<oTable.rows.length;i++){
for(j=0;j<oTable.rows[i].cells.length;j++){
s+=oTable.rows[i].cells[j].firstChild.value+' '
}
s+='\n'
}
alert(s)
}
</script>
<input type=button onclick="getValue(t)" value=get>
this.parentElement返回所在的td
this.parentElement.parentElement返回tr
this.parentElement.parentElement.rowIndex返回该行的行标(从0开始)
parentElement 用的是DHTML方法,parentNode/ 用的是dom 方法。两者可以结合起来适用。正如我上面讲的。this.parentNode.parentNode.rowIndex=this.parentElement.parentElement.rowIndex;
你可以多看一些dhtml dom方面的资料就知道了。没什么难得。只是你现在还没有完全明白。等你理解之后就知道了!
alert(this.parentNode.tagName)
alert(this.parentNode.parentNode.tagName);
alert(this.parentNode.parentNode.parentNode.tagName);分别看每一层里面的东西就知道了!看看是什么元素!
怎么样使其保留原来的值呢?
如二行为:
<tr>
<td width="10%">
<input type="radio" name="radiobutton" value="1">
</td>
<td width="16%">
<input name="datafield" size="8" value="test1">
</td>
<td width="11%">
<input type="checkbox" name="show" value="checkbox" >
</td>
<td width="23%">
<input type="checkbox" name="grouped" value="checkbox" checked>
</td>
<td width="40%" class="">
<select name="aggregation">
<option value="CountAggregation" selected >计数</option> </select>
<a onClick=AddResult(this.parentElement.parentElement.rowIndex) href="#">添加</a></td>
</tr> <tr>
<td width="10%">
<input type="radio" name="radiobutton" value="1">
</td>
<td width="16%">
<input name="datafield" size="8" value="test2">
</td>
<td width="11%">
<input type="checkbox" name="show" value="checkbox" >
</td>
<td width="23%">
<input type="checkbox" name="grouped" value="checkbox" checked>
</td>
<td width="40%" class="">
<select name="aggregation">
<option value="SumAggregation" selected >汇总</option>
<option value="CountAggregation" >计数</option> </select>
<a onClick=AddResult(this.parentElement.parentElement.rowIndex) href="#">添加</a></td>
</tr>
解决了这个问题,就结分了。
<form name=frm>
<input name=txt><input name=txt onblur="alert(frm.txt[0].value+' '+frm.txt[1].value)">
</form>
名字相同访问时就当数组访问,你的先取得rowIndex,这样form1.username[rowIndex].value就可以了,当然,具体点是否对应(form1.username[rowIndex+1].value)
(保留用户操作后的内容)
如用cloneNode,好像是初始值,并不是用户操作后的内容。