Javascript table tr deletes on tr (Dynamic tr delete and re-generate tr id)

后端 未结 1 425
遥遥无期
遥遥无期 2021-01-28 07:02

I have a code which deletes a tr and regenerate tr\'s id sequence wise. But It works on tr click and I want to do this on a button click. How I do this.

Here is my code<

相关标签:
1条回答
  • 2021-01-28 07:44

    First thing is - Ideally you shouldn't put the same id values of all the rows. id is for unique identifier in the entire DOM.

    Next is - As you are doing with $(tr), it will take the entire row.

    You can try something like:

            $("[name=btn]").click(function () {
                $(this).parents('tr').remove();
            });
    

    to remove the desired row on click of the button.

    For rest of the manipulations, you can add your logic.

    0 讨论(0)
提交回复
热议问题