gpt4 book ai didi

javascript - 使用附加函数js无法读取选择标签上的类属性

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:52 25 4
gpt4 key购买 nike

我创建了一个动态表,通过单击按钮,每次按下按钮时都会生成一个新行。一切都按预期工作,但选择标记或任何其他输入中的类属性无法正常工作。我如何让它发挥作用。有什么想法吗??

以下是 .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();

});
});

最佳答案

由于您要动态添加选择,因此您需要了解 delegated events

Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

选择你选择这样的类(class)

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

关于javascript - 使用附加函数js无法读取选择标签上的类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41328241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com