开发者

Dynamic Table Row Deletion

I am creating a dynamic table through Javascript. I am taking no. of row and columns from user and creating table. On second time when user enters I am deleting all present rows and creating new rows. Everything is working fine but for deletion when I am using the commented cod开发者_运维技巧e it is not working while other one is working fine. Can anybody tell me what is the reason behind this?

//deleting preExisting rows:-

for(k=tblObj.rows.length;k>0;k--)
tblObj.deleteRow(k-1);

Above Logic is working fine but below one is not working why???

            /*for(k=0;k<Number(tblObj.rows.length);k++)
                {   
                    tblObj.deleteRow(k);
                }*/   //This Logic is not working:Why???


The tblObj.rows.length value is computed for every loop execution, and the array is getting shorter every time.

Try with

var len = tblObj.rows.length;
for(k=0;k<len;k++)
{   
    tblObj.deleteRow(0);
}


If you are deleting rows from the beginning you have to delete first row rowCount times:

var rowCount = tblObj.rows.length;
for(k=0;k<rowCount;k++)
{   
    tblObj.deleteRow(0);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜