动态内容选择不起作用 $(document).on('keydown','.lst',函数(e){ var代码=(e.keyCode?e.keyCode:e.which); 如果(代码==13){ html=''; html+=''+i+''; html+=''; html+=''; html+=''; html+=''; html+=''; html+=''; html+=''; $('table').append(html); $.ajax({ 类型:“post”, url:“pages/get_products.php”, 数据:html, 数据类型:“html”,//希望返回html 成功:功能(响应){ $('#code"+i).html(回应); } }); $('.selectpicker').selectpicker({size:4}); $('.selectpicker').focus().select(); i++; } });

动态内容选择不起作用 $(document).on('keydown','.lst',函数(e){ var代码=(e.keyCode?e.keyCode:e.which); 如果(代码==13){ html=''; html+=''+i+''; html+=''; html+=''; html+=''; html+=''; html+=''; html+=''; html+=''; $('table').append(html); $.ajax({ 类型:“post”, url:“pages/get_products.php”, 数据:html, 数据类型:“html”,//希望返回html 成功:功能(响应){ $('#code"+i).html(回应); } }); $('.selectpicker').selectpicker({size:4}); $('.selectpicker').focus().select(); i++; } });,php,jquery,ajax,Php,Jquery,Ajax,get_products.php $(document).on('keydown', '.lst', function (e) { var code = (e.keyCode ? e.keyCode : e.which); if (code == 13) { html = '<tr>'; html += '<td>' + i + '</td>'; html += '<td><se

get_products.php

$(document).on('keydown', '.lst', function (e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
        html = '<tr>';
        html += '<td>' + i + '</td>';
        html += '<td><select class="inputs form-control selectpicker prd" data-live-search="true" name="code_' + i + '" id="code_' + i + '"></select></td>';
        html += '<td><input type="text" class="inputs form-control" name="price_' + i + '" id="price_' + i + '" /></td>';
        html += '<td><input type="text" class="inputs form-control" name="qty_' + i + '" id="qty_' + i + '" /></td>';
        html += '<td><input type="text" class="inputs form-control" name="disc_' + i + '" id="disc_' + i + '" /></td>';
        html += '<td><input type="text" class="inputs form-control" name="tax_' + i + '" id="tax_' + i + '" /></td>';
        html += '<td><input type="text" class="inputs form-control lst" name="total_' + i + '" id="total_' + i + '" /></td>';
        html += '</tr>';
        $('table').append(html);

             $.ajax({    
                            type: "post",
                            url: "pages/get_products.php", 
                            data: html,
                            dataType: "html",   //expect html to be returned                
                            success: function(response){                    
                                $('#code_' + i).html(response); 
                            }
                    });

        $('.selectpicker').selectpicker({ size: 4});
        $('.selectpicker').focus().select();
        i++;
    }
});

尝试添加以下行:

<?php
session_start();
ob_start();
require "../model/configuration.php";
?>
<?php
$queryprd=$db->execute("select * from product_add where delet='0'");
while($result=$queryprd->fetch_assoc())
{
?>
<option value="<?php echo $result['productcode']."|".$result['productname'];?>"><?php echo $result['productcode']."&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;".$result['productname'];?></option>
<?php
}
?>
在AJAX success函数中,将“
.selectpicker
”更改为“
#code"”+i.selectpicker

通常您必须添加选择器参数,否则事件将直接绑定而不是委派,这仅在元素已经存在的情况下有效(因此它不适用于动态加载的内容)

例如:
。单击(“click”,函数(事件){

但是使用
selectpicker()
我认为这是不可能的

您可以选择:
。选择选择器(“刷新”);

//删除或添加选项时,或者 通过JavaScript禁用/启用select

更新

根据您的演示,您应该使用:

  $('.selectpicker').selectpicker({ size: 4});
  $('.selectpicker').focus().select();
  i++;
因为在中有一个由
selectpicker
动态创建的内容。您必须将数据附加到适当的元素(

    为此,您需要首先使用以下方法创建de
    选择器选择器

    $('#code_'+i).sibiling('.inputs').find('.selecticker').html(response);
    
    然后附加其中的内容,然后更新选择器:

    $('.selectpicker').selectpicker({ size: 4});
    $('.selectpicker').focus().select();
    i++;
    

    $('#code_'+i+'.selectpicker')。selectpicker({size:4});
    $('#code_'+i+'.selectpicker')。focus().select();
    i++;
    $('#code_'+i+'.selectpicker')。selectpicker
    ,然后您也可以这样做:
    $('.#code>$)(#code_'+i'.selectpicker')。selecter')。selecter($)。selecter')。selecter('refresh'+code++.selecter'))
    希望有帮助。检查此演示,按enter键进入每个输入字段选择器选择器正在工作,但选项未加载,对吗?是的,这是我的问题
    $('.selectpicker').selectpicker('refresh');