Using a changing variable in JQuery's nextAll()

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[0]" to "column_name[1]". 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).parents(\"tr.deletable\").remove(); 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[2] would change to column_name[1]. 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准