これが私がやろうとしていることです:
- 誰かが入力フィールドにテキストを入力する
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>
経由で追加された入力に焦点を合わせていないだけで$.get
、修正方法がわかりません。次の入力フィールドをページに追加していますが、フォーカスしていません。