我有一份与会者名单,其中包含已填写活动表格的记录。每个表行都附有一个删除按钮,以便管理员可以从数据库中删除记录。我已经尝试在单击删除按钮时将确认对话框(是/否)附加到表单。
在我附加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');
});
有人能告诉我哪里出错了吗?感谢
答案 0 :(得分:0)
点击任何带有“删除按钮”类的内容时,以下脚本会弹出一个JavaScript对话框。如果用户单击“是”,则应用程序将继续执行默认操作,如果用户单击“否”,则应用程序将停止应该执行的操作。
$('.delete-button').click(function () {
return window.confirm("Attendee will be deleted! Please Confirm.');
});
您也可以使用原始脚本执行此操作,您唯一需要的是,如果您希望它继续使用默认值,则返回true;如果您希望它停止,则返回false。
编辑:我认为应该这样做:$('.delete-button').on('click', function(e){
$('<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() {
var result = true;
$(this).dialog("close");
}, "No": function() {
var result = false;
$(this).dialog("close");
}
}
return result;
});