请告诉我哪里错了,以便我纠正?它没有给出错误它应该在删除记录之前显示确认窗口,但它直接删除记录
<script type="text/javascript">
var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) {
if (!confirm('Are you sure?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', confirmIt, false);
}
</script>
删除链接:
<a href='".$_SERVER['PHP_SELF']."?action=delete&id=$id' class='confirmation'> Delete</a>
删除功能:
if(isset($_GET['action']) && trim($_GET['action'])=="delete")
{
$del="delete from contacts where id='".$_GET['id']."'";
mysql_query($del) or die(mysql_error());
header("Location: mainpage.php");
}