Event delegate issue for dynamically added element in jquery

后端 未结 3 647
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 05:40

HTML

Col :
3条回答
  •  爱一瞬间的悲伤
    2020-12-12 06:35

    You need to assign the on handler against an ancestor element, for example the document element. Then you can specify the exact selector for the element to listen for as the second parameter:

    $(document).on('change', '.check-input', function () {
        $(this).next().text('Error');
    });
    

    This basically means: Listen for the change event for all .check-input elements that are descendants of the document element.

    Here is a working example

提交回复
热议问题