ie6在表的特定行索引处插入行 [英] ie6 Insert Row at specific Row Index of Table
问题描述
有人可以告诉我如何在
已经创建的表的任何给定行索引处插入行吗?它只需要在IE6中工作(在内部网上使用
工作)。
具体来说,如果一个表总共20行(认为他会有所不同) ),
,有人想在第5行插入一个新行,我需要添加一行
,并且每行从5-20开始"克隆"到6-21。
第5行的内容也可能有所不同;它不是
现有行的直接副本。
我看到过这样做的东西,但它使用了innerHTML,
,我读过这对于桌子来说是不可能的。
谢谢,
Ann
Giggle Girl写道:有人能告诉我如何在已经创建的表的任何给定行索引处插入行吗?它只需要在IE6中工作(在内部网上用于工作)。
具体来说,如果一个表总共20行(以为他会有所不同),
和某人想要在第5行插入新行,我需要添加一行,并且要从5-20中的每一行克隆。到6-21。
在DOM中找到表元素并使用insertRow(index)插入
行。
-
Ian Collins。
Ian Collins写道:
Giggle女孩写道:有人能告诉我如何在已经创建的表的任何给定行索引处插入一行吗?它只需要在IE6中工作(在内部网上用于工作)。
具体来说,如果一个表总共20行(以为他会有所不同),
和某人想要在第5行插入新行,我需要添加一行,并且要从5-20中的每一行克隆。到6-21。
在DOM中找到表元素并使用insertRow(index)插入行。
并确保将其作为'thead''或'tbody''
元素的子元素插入。
PointedEars
< br>
Thomas''PointedEars''Lahn写道:
具体来说,如果一个表是20行总数(以为他会有所不同),
有人想在第5行插入一个新行,我需要添加一行,并且每行需要5-20行"克隆"到6-21。
在DOM中找到表元素并使用insertRow(index)插入行。
>并确保将其作为'thead'或'tbody''
元素的子元素插入。
不必要,我认为是完全错误的,insertRow是一个HTMLTableElement
方法,如果表为空,它会添加一个tbody。否则它会将
添加到与索引对应的表格部分。
试试这个:
HTML:
< table id =''test1''>
< / table>
< table id = ''test2''>
< tbody>
< tr>
< td name =''cell0''/ >
< tr>
< tr>
< td name =''cell1''/>
< tr>
< tbody>
< / table>
脚本:
var test1 = document.getElementById(''test1'');
test1.insertRow(-1);
alert(test1.innerHTML);
var test2 = document.getElementById(''test2'');
var row = test2.insertRow(1);
var cell = row.insertCell(-1);
cell.name =''cell2'';
alert(test2.innerHTML);
-
Ian Collins。
Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.
The contents of row 5 may vary as well; it is not a straight copy of an
exisiting row.
I have seen something that did this very thing, but it used innerHTML,
and I have read this is inavisable for tables.
Thanks,
Ann
解决方案Giggle Girl wrote:Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.
Locate the table element in the DOM and use insertRow( index ) to insert
the row.
--
Ian Collins.
Ian Collins wrote:
Giggle Girl wrote:Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.
Locate the table element in the DOM and use insertRow( index ) to insert
the row.
And be sure that you insert it as child element of a `thead'' or `tbody''
element.
PointedEars
Thomas ''PointedEars'' Lahn wrote:
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.
Locate the table element in the DOM and use insertRow( index ) to insert
the row.
And be sure that you insert it as child element of a `thead'' or `tbody''
element.
Unnecessary and I think plain wrong, insertRow is an HTMLTableElement
method and it adds a tbody if the table is empty. Otherwise it will add
to the table section corresponding to the index.
Try this:
HTML:
<table id=''test1''>
</table>
<table id=''test2''>
<tbody>
<tr>
<td name=''cell0''/>
<tr>
<tr>
<td name=''cell1''/>
<tr>
<tbody>
</table>
Script:
var test1 = document.getElementById(''test1'');
test1.insertRow(-1);
alert(test1.innerHTML);
var test2 = document.getElementById(''test2'');
var row = test2.insertRow(1);
var cell = row.insertCell(-1);
cell.name = ''cell2'';
alert(test2.innerHTML);
--
Ian Collins.
这篇关于ie6在表的特定行索引处插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!