PHP, MySQL, & jQuery를 사용하여 간단한 작업 관리자 응용 프로그램을 만들고 있습니다. 사용자가 "새 작업"버튼을 클릭하고 텍스트 필드에 타이핑하고 엔터를 치면 작업을 추가 할 수있는 기능이 추가됩니다. 이것은 JQuery와 나는이 : 나는 index.php 파일에 하드 코드 된 형태가있는 경우 예상대로이 기능이 작동동적 양식이 제출되지 않음 (jQuery)
function add_task() {
// Add the "add new task" button
$("<span class='add-new'>Add new item</span>").appendTo(".sub-phase");
// String for the input form
var task_form = '<form class="add-new-task" autocomplete="off"><input type="text" name="new-task" placeholder="Add a new item..." /></form>';
// Display form on button click
$('.add-new').click(function() {
$(task_form).appendTo($(this).parent());
});
// Post results
$('.add-new-task').submit(function(){
var new_task = $('.add-new-task input[name=new-task]').val();
if(new_task != ''){
$.post('includes/add-tasks.php', { task: new_task }, function(data) {
$('.add-new-task input[name=new-task]').val('');
$(data).appendTo('.task-list').hide().fadeIn();
});
}
return false;
});
}
. 그러나 양식을 여기 jQuery에서 만든 경우 여기에 아무 것도 제출하지 않습니다. 나는 주변을 수색했으나 효과가있는 해결책을 찾을 수 없었다.
많은 조언을드립니다. 고맙습니다.
$ ('')을 사용해 보셨습니까? .addClass ('add-new'); –