请告诉我哪里错了,以便我能纠正错误?它没有给出错误它应该在删除记录之前显示确认窗口,但它直接删除记录
<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");
}
答案 0 :(得分:1)
如果您不想在点击链接时激活该链接,则onclick必须返回false。