Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 为什么动态创建的元素的类无法识别?_Jquery_Jquery Ui_Class_Dynamically Generated - Fatal编程技术网

Jquery 为什么动态创建的元素的类无法识别?

Jquery 为什么动态创建的元素的类无法识别?,jquery,jquery-ui,class,dynamically-generated,Jquery,Jquery Ui,Class,Dynamically Generated,我有一个文本框。如果选中并按tab键,将打开新行。到目前为止,这一切都很好。但是,相同的操作在动态创建的文本框中不起作用。即使它具有调用原始textbox的相同类。我试图在网上找到解释,但我找不到正确的答案。谁能帮帮我吗 $('.list').keydown(函数(键){ if(key.which==9){ $('.components_list')。追加(''); } }); 使用$(文档)。在上以动态创建的元素为目标: $(document).on('keydown', '.list',

我有一个文本框。如果选中并按tab键,将打开新行。到目前为止,这一切都很好。但是,相同的操作在动态创建的文本框中不起作用。即使它具有调用原始textbox的相同类。我试图在网上找到解释,但我找不到正确的答案。谁能帮帮我吗

$('.list').keydown(函数(键){
if(key.which==9){
$('.components_list')。追加('
  • '); } });
    使用
    $(文档)。在
    上以动态创建的元素为目标:

    $(document).on('keydown', '.list', function(key){
        if(key.which === 9) {
            $('.ingredients_list').append('<li><input class="list" type="text"/><i><img class="remove" src="images/remove.svg"></i></li>');
    
        }
    }); 
    
    $(文档).on('keydown','.list',函数(键){
    if(key.which==9){
    $('.components_list')。追加('
  • '); } });
    .

    使用
    $(文档)。在
    上以动态创建的元素为目标:

    $(document).on('keydown', '.list', function(key){
        if(key.which === 9) {
            $('.ingredients_list').append('<li><input class="list" type="text"/><i><img class="remove" src="images/remove.svg"></i></li>');
    
        }
    }); 
    
    $(文档).on('keydown','.list',函数(键){
    if(key.which==9){
    $('.components_list')。追加('
  • '); } });

    .

    这是因为您需要将事件委派用作新的
    。在执行
    .keydown()
    时,列表
    元素不存在,请将代码更改为:

    $(document).on('keydown','.list',function(key){
            if(key.which === 9) {
                $('.ingredients_list').append('<li><input class="list" type="text"/><i><img class="remove" src="images/remove.svg"></i></li>');
    
            }
        }); 
    
    $(文档).on('keydown','.list',函数(键){
    if(key.which==9){
    $('.components_list')。追加('
  • '); } });

    这是因为您需要将事件委派用作新的
    。在执行
    .keydown()
    时,列表
    元素不存在。请将代码更改为:

    $(document).on('keydown','.list',function(key){
            if(key.which === 9) {
                $('.ingredients_list').append('<li><input class="list" type="text"/><i><img class="remove" src="images/remove.svg"></i></li>');
    
            }
        }); 
    
    $(文档).on('keydown','.list',函数(键){
    if(key.which==9){
    $('.components_list')。追加('
  • '); } });