jQuery cannot recognize appended cloned elements using jQuery.appendTo()

后端 未结 3 1844
一生所求
一生所求 2021-01-20 06:04

I want to make a list of group inputs allow user to dynamically let user add/remove group row:

3条回答
  •  囚心锁ツ
    2021-01-20 07:08

    The problem is a matter of order and when expressions are evaluated. When you call jQuery with a selector, the selector is evaluated at that time to select the matching elements which exist at that time. The click handler is then registered to only those elements. Elements which are created later are, naturally, not affected.

    One solution, demonstrated in another example, uses jQuery's "live events" to apply the selector at the time each event is fired to determine what elements, if any, it would match. There is a performance implication to this approach.

    Another solution is to register the desired event handler on the newly created elements when you create them.

提交回复
热议问题