Javascript ID中具有跳过序列的动态控件

Javascript ID中具有跳过序列的动态控件,javascript,html,Javascript,Html,我正在使用JavaScript向HTML页面动态添加一些控件。假设我有这个 ID Name Type Is Valid (TextBox) (Select/DropDown) (CheckBox) --- ------------ --------------------- ---------- 1 txtName_1 ddlType_1 chkValid_1 2

我正在使用JavaScript向HTML页面动态添加一些控件。假设我有这个

ID   Name          Type                   Is Valid
     (TextBox)     (Select/DropDown)      (CheckBox)
---  ------------  ---------------------  ----------
1    txtName_1     ddlType_1              chkValid_1
2    txtName_2     ddlType_2              chkValid_2
3    txtName_3     ddlType_3              chkValid_3
4    txtName_4     ddlType_4              chkValid_4
现在我删除一些行(例如ID为3的行)并添加一些新行。新控件的名称为(“txtName_”+“最后一行ID”+1)。因此,它可能成为

ID   Name          Type                   Is Valid
     (TextBox)     (Select/DropDown)      (CheckBox)
---  ------------  ---------------------  ----------
1    txtName_1     ddlType_1              chkValid_1
2    txtName_2     ddlType_2              chkValid_2
4    txtName_4     ddlType_4              chkValid_4
5    txtName_5     ddlType_5              chkValid_5

现在,我想在for循环(1到“最后一行ID”)中迭代这些控件,以生成一个连接字符串如何在循环中跳过这些已删除的ID?

通过应用本SO帖子中的概念,可以在循环中按如下方式检查带有跳过编号的控件ID

var i;
for (i = 1; i <= lastRowID; i++;)
{
    var element =  document.getElementById('txtName'+i);
    if (typeof(element) != 'undefined' && element != null)
    {
        // control with this ID exists.
    } else {
        // control with this ID does NOT exist, SKIP it.
    }
}
vari;
对于(i=1;i