我有一个与会者名单,其中记录了谁填写了活动表格。每个表行都附加了一个删除按钮,以便管理员可以从数据库中删除一条记录。单击删除按钮时,我尝试将确认对话框(是/否)附加到表单。
在我附加 javascript 之前,它正在删除一条记录,但现在虽然对话框出现并且可以正常工作,但它并没有删除记录。这是我的代码:
<form id="attending" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table class="attendees">
<thead>
<tr>
<th class="name">Name</th>
<th class="company">Company</th>
<th class="email">Email</th>
<th class="contact">Contact</th>
<th class="day">Day</th>
<th class="time">Time</th>
<th class="delete"> </th>
</tr>
</thead>
<?php while ($row = mysql_fetch_assoc($result)) { ?>
<tr>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<td class="name"><?php echo $row['name']; ?></td>
<td class="company"><?php echo $row['company']; ?></td>
<td class="email"><?php echo $row['email']; ?></td>
<td class="contact"><?php echo $row['contact']; ?></td>
<td class="day"><?php echo $row['day']; ?></td>
<td class="time"><?php echo $row['event-time']; ?></td>
<td class="delete"><input type="submit" name="delete" class="delete-button" value="Delete"> </td>
</tr>
<?php if(isset($_POST['delete'])) {
$id = $_POST['id'];
mysql_query("DELETE FROM `registered_blue` WHERE `id` = '$id' ");
}
?>
<?php } ?>
</table>
</form>
这是我的jquery,如下:
var confirmDelete = $('<div></div>')
.html('Record will be deleted! This operation can\'t be undone. <br />Are you sure?')
.dialog({
autoOpen: false,
title: 'Attendee will be deleted! Please Confirm.',
buttons: {"Yes": function() {
$(this).dialog("close");
$('#attending').submit();
}, "No": function() {
$(this).dialog("close");
}
}
});
$('.delete-button').on('click', function(e){
e.preventDefault();
$(confirmDelete).dialog('open');
});
有人可以告诉我哪里出错了吗?谢谢