With jquery, I'm dynamically adding rows. To do this, I'm copying the first
of the table and then with some regex I'm changing the names and sometimes ids from thing like "column\_name" to "column_name". This is the regex that I'm using:
newRow = newRow.replace(new RegExp("\\[[0-9]+][\"\']", "gm"), "[" + $("#rowNum").val() + "]\"");
This is working fine.
I'm also adding a link to dynamically delete this line. This delete link has the following JQuery executed upon a click:
This is also working fine.
Now, my problem is when a user adds 3 rows, and then deletes the first row. I want the second two rows to decrement their index number. For example column\_name would change to column_name. How should I go about doing this? Here's what I've been trying so far:
$(this).parents("tr.deletable").nextAll().html().replace(new RegExp("\\[[0-9]+][\"\']", "gm"), "[" + i + "]\"");
I have i set to 50 just to see if it successfully puts that in as the new index but it does not. I haven't figured out smoothly get the decremented value. The above code does not work.
Does anyone have any suggestions on how I can accomplish this?
As for why I need to do this, it's because I'm using Java Struts and it requires all the form elements to have a name with a proper index at the end. Are you sure it doesn't just work with fieldname ?
以上就是Using a changing variable in JQuery's nextAll()的详细内容，更多请关注web前端其它相关文章！