Add & Subtract TR on Button Click (ID +1)

Hey I'm looking to have a table of products for an order form. I would like the user to be able to add & subtract rows (adding & removing products w/ qty & remarks.) I have pieced this together and works with a few exceptions. - I need the ID of each input to +1 while val('') on the new inputs/row. - The subtract button works but removes the last & only row. Removing itself & the add button with it. Could anyone show me some examples of how I would +1 the inputs & have the subtract button show on the 2nd row? Or lead me in the right direction? Thanks in advance- HTML:
Item Qty. Remarks
What I'm using now: $("#add").click(function() { $('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last'); $('#mytable tbody>tr:last #product').val(''); $('#mytable tbody>tr:last #qty').val(''); $('#mytable tbody>tr:last #remarks').val(''); $('#mytable tbody>tr:last #add').val('+'); $("input.subtract").click(function() { $(this).closest("tr").remove(); });

以上就是Add & Subtract TR on Button Click (ID +1)的详细内容,更多请关注web前端其它相关文章!

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

评论 抢沙发

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

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

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏