Javascript 将id增加为1

Javascript 将id增加为1,javascript,Javascript,我想要以下内容:当用户单击按钮时,id必须增加1。现在,我使用了一个熟悉的函数为我的行指定唯一的id,并且工作正常。现在,我对唯一的输入字段使用了相同的代码片段,但这不起作用。同样奇怪的是,下面的代码正确地处理了name属性 clone.find('#dsmeta_image_caption').prop('name', 'dsmeta_image_caption[' + row.length + ']'); // we now need to set the new ID for th

我想要以下内容:当用户单击按钮时,id必须增加1。现在,我使用了一个熟悉的函数为我的行指定唯一的id,并且工作正常。现在,我对唯一的输入字段使用了相同的代码片段,但这不起作用。同样奇怪的是,下面的代码正确地处理了name属性

    clone.find('#dsmeta_image_caption').prop('name', 'dsmeta_image_caption[' + row.length + ']'); // we now need to set the new ID for the row - ID's cannot be duplicated. This again will use the row.length
所以我想要的是将每个字段id增加1

代码JS:

function create_row_event(event) {
    // Declared variable
    var row = jQuery('tbody tr.row');
    var clone = row.last().clone(true);

    // Find the cloned fields and reset the values of it
    clone.find('input[type=text], text, textarea, select, input.upload_image').val(''); // Reset the values
    clone.find('.preview_image').attr('src', ''); // Reset the values


    row.parent('tbody.ui-sortable').append(clone); // Append the new row to the body
    clone.prop('id', 'repeatable-[' + row.length + ']'); // we now need to set the new ID for the row - ID's cannot be duplicated. This again will use the row.length
            clone.find('input#dsmeta_image_caption').prop('id', '[' + row.length + ']');


}
在这里您可以看到代码:

查找('#id')操作将不起作用,因为其中涉及重复的id。一旦文档中存在重复的ID,您就不能期望基于ID的选择器/过滤器正常工作

改用例如
find('input:text')
,它会起作用