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()时,实际上没有创建下一个输入元素之所以执行code>,是因为您正在使用AJAX调用来创建它。您还需要家长的下一个元素。您能在上面重现问题并链接到它吗?如果人们能够自己运行代码,那么他们就更容易提供帮助。不应该$(this).next('input[type=text]')).focus()
be$parent.next('input[type=text]').focus()代码>?您的代码不工作。我知道这就是问题所在,在调用next()
函数之前,我需要使新元素live
,但我不知道如何做到这一点。您正在检查此元素的下一个元素,但实际上它应该是父元素的下一个元素。。。