Javascript警报单击以删除在IE8中不起作用
Javascript alert click to delete not working in IE8
我有一个JavaScript,当我点击删除时,它会弹出确认,在我删除之前,它在Mozilla Firefox和Google Chrome中运行良好。但是当我在IE8中单击删除时,它会弹出显示确认,并且当文件被删除时,它拒绝删除。有人有解决方法吗?这是我下面的片段
触发
<?php echo '<td><a href="delete.php?staff_id=' . $row['staff_id'] . '"><input type="button" onclick="confirmDelete(event)" value="delete"></a></td>'; ?></td>
删除确认代码段
function confirmDelete(e) {
if(confirm('Are you sure you want to delete this Record?'))
alert('Record Deleted !');
else {
alert('Cancelled !');
e.preventDefault();
}
}
</script>
我认为IE 8不喜欢链接内的<输入>标签。您可以将 onclick 处理程序添加到""标记中:输入>
<?php echo '<td><a href="delete.php?staff_id=' . $row['staff_id'] . '" onclick="confirmDelete(event)">Delete</a></td>'; ?>
顺便说一句:你有两个",一个在php块之外。
编辑
第二个想法:当删除操作更改应用程序的状态时,最好"发布"数据。所以更好的方法是:
<form action="delete.php" method="post" onsubmit="confirmDelete(event)">
<div>
<input type="hidden" name="staff_id" value="<?php echo $row['staff_id']; ?>" />
<input type="submit" name="submit" value="Delete" />
</div>
</form>
在 PHP 中,您可以通过 $_POST['staff_id'] 访问staff_id。
编辑2:
更新了javascript,两种方法(链接和按钮):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>test</title>
<script type="text/javascript">
//<![CDATA[
function confirmDelete() {
if (!confirm('Delete?')) {
return false;
}
return true;
}
//]]>
</script>
</head>
<body>
<h1>Version 1 (link)</h1>
<div>
<a href="delete.php?staff_id=1" onclick="return confirmDelete()">Delete</a>
</div>
<h1>Version 2 (button)</h1>
<form action="delete.php" method="post" onsubmit="return confirmDelete()">
<div>
<input type="hidden" name="staff_id" value="<?php echo $row['staff_id']; ?>" />
<input type="submit" name="submit" value="Delete" />
</div>
</form>
</body>
</html>
在IE 7-10和FF中测试。
问候
发生这种情况是因为 FF 和 IE 以不同的方式冒泡点击事件。
问题是您的按钮位于标签内,该标签具有自己的点击处理程序。
你应该尝试这样的事情:
<a href="delete.php?id=1" onclick="confirmDelete(event)">delete</a>
甚至更简单:
<a href="delete.php?id=1" onclick="return confirm('Are you sure?')">delete</a>
这将在所有浏览器中以相同的方式工作。
当我们从数据库中删除任何内容时,您也可以使用两次确认消息。这是代码
function confirmDelete() {
var cont = false;
cont = confirm('Warning! Delete this membership level?')
if (!cont) {
return false;
}
cont = confirm('Last Warning! Are you really sure?'nDeleting this membership level cannot be undone!');
if (!cont) {
return false;
}
return true;
}
<a href="action=delete_level&id=<?php echo $member_level; ?>" onclick="return confirmDelete()">Delete</a>
谢谢。。
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- 如果我添加 pageX 页面 Y 在 IE8 中不起作用<!文档类型 html>.
- getElementsByTagName和getElementsByClassName在IE8中不起作用
- 导航在IE8上不起作用