我正在研究一个简单的列表管理器,以使用jQuery学习PHP。我无法将待办事项的值传递给脚本。结果,我无法删除项目。
我是jQuery的新手,但尝试使用Google :)寻找解决方案。不幸的是没有成功。
html通过脚本解析
tasks.forEach(task => {
template += `
<tr>
<td>${task.id}</td>
<td>
<a href="#" class="task-item">
${task.name}
</a>
</td>
<td>${task.description}</td>
<td>
<button value="${task.id}" class="task-delete btn btn-danger">
Delete
</button>
</td>
</tr>
`
});
//script with the delete function
$(document).on('click', '.task-delete', (e) => {
console.log('FetchTaskCheckDelete1!');
if(confirm('Are you sure you want to delete it?')) {
const element = $(this)[0].activeElement.parentElement;
var element2 = $(this).attr("value");
const id = $(element).attr("id");
console.log('FetchTaskCheckDelete2!');
console.log(element);
console.log(element2);
console.log(id);
$.post('task-delete.php', {id}, (response) => {
fetchTasks();
});
}
});