类属性未使用附录函数JS上的选择标签读取



我已经创建了一个动态表,每次按下按钮时,单击一个按钮将生成新行。除了选择标签或任何其他输入中的类属性外,一切都可以正常工作。我如何使它工作。任何想法??

这是可行的.js代码,并在按钮上添加新行:

        $('.plusbtn12').click(function () {
            $(".quoteTable12").append('<tr><td><select class="js-select2 form-control c_solutions" name="i_solution[]" style="width: 100%;" data-placeholder="Choose one.."></select></td><td class="hidden-xs"><input class="form-control" type="text" name="i_quantity[]" placeholder="Quantity"></td><td><input class="form-control c_costing" type="text" name="i_cost[]" placeholder="Cost"></td></tr>');
            var options = "";
            $.getJSON("getSolution12.php", function (data) {
                for (i = 0; i < data.length; i++) {
                    options += "<option>" + data[i] + "</option>";
                }
                $('.quoteTable12 tr:last').find('.c_solutions').html("");
                $('.quoteTable12 tr:last').find('.c_solutions').append(options);
                $(".c_solutions").change();
            });
        });

由于您要动态添加选择,因此您需要了解委派事件

描述: 将处理程序附加到一个或多个事件,以基于一个或将来的所有元素,基于一个匹配选择器的元素 特定的根元素集。

选择您选择类似这样的类

$( document ).on( "click", ".js-select2", function() {
  console.log( "hey" );
});

最新更新