Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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
Php 刚刚添加的元素上的jquery next()_Php_Jquery_Next - Fatal编程技术网

Php 刚刚添加的元素上的jquery next()

Php 刚刚添加的元素上的jquery next(),php,jquery,next,Php,Jquery,Next,以下是我想要发生的事情: 有人在输入字段中输入文本 当他们在键盘上点击ENTER时,它会使用AFTER()函数在当前输入字段后添加一个输入字段,然后聚焦该输入字段,以便他们可以继续键入并反复执行此操作 以下是我的代码,它不起作用: $('.table-todo input[type=text]').live('keypress', function (e) { if (e.which == 13) { $parent = $(this).parent(

以下是我想要发生的事情:

  • 有人在输入字段中输入文本
  • 当他们在键盘上点击
    ENTER
    时,它会使用
    AFTER()
    函数在当前输入字段后添加一个输入字段,然后聚焦该输入字段,以便他们可以继续键入并反复执行此操作
以下是我的代码,它不起作用:

$('.table-todo input[type=text]').live('keypress', function (e) {   
    if (e.which == 13) 
    {
        $parent = $(this).parent('.field');     
        $.get('projects-add-task.php?show_delete=yes', function (data) { $parent.after(data); }, 'html');
        $(this).next('input[type=text]').focus();
    }
});
以下是
projects add task.php
的内容:

<div class="field">
<input type="text" name="task[]" />
<a href="#" title="Add Task Below" class="todo-add"><img src="images/icon-todo-add.png" alt="" onmouseover="this.src='images/icon-todo-add-h.png'" onmouseout="this.src='images/icon-todo-add.png'" /></a>
<?php if ($_GET['show_delete'] == 'yes') { ?>
<a href="#" title="Delete This Task" class="todo-delete"><img src="images/icon-todo-delete.png" alt="" onmouseover="this.src='images/icon-todo-delete-h.png'" onmouseout="this.src='images/icon-todo-delete.png'" /></a>
<?php } else { ?>
<img src="images/icon-todo-delete-o.png" alt="" />
<?php } ?>
<div style="clear: both;"></div>
</div>


它只是没有关注通过
$添加的输入。获取
,我不知道如何修复它。它会将下一个输入字段添加到页面,但不会对其进行聚焦。

您可以这样做:

    $parent = $(this).parent('.field');    
    $this = $(this);
    $.get('projects-add-task.php?show_delete=yes', function (data) { 
        $parent.after(data); 
        $parent.next().children('input[type=text]').focus();
    }, 'html');

问题是,当
$(this).next('input[type=text]').focus()时,实际上没有创建下一个输入元素,是因为您正在使用AJAX调用来创建它。您还需要家长的下一个元素。

您能在上面重现问题并链接到它吗?如果人们能够自己运行代码,那么他们就更容易提供帮助。不应该
$(this).next('input[type=text]')).focus()
be
$parent.next('input[type=text]').focus()?您的代码不工作。我知道这就是问题所在,在调用
next()
函数之前,我需要使新元素
live
,但我不知道如何做到这一点。您正在检查此元素的下一个元素,但实际上它应该是父元素的下一个元素。。。