需求:用户点击删除按钮时,弹出一个确定框,如果用户点击“确定”执行删除操作,否则不执行
js代码
function del() {
var msg = "您真的确定要删除吗?\n\n请确认!";
if (confirm(msg)==true){
return true;
}else{
return false;
}
}
html代码
<a href="" onclick="javascript:return del();">删除</a>
方法二:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>确认是否删除</title>
<script type="text/javascript">
function del(){
if(!confirm("确认要删除?")){
window.event.returnvalue = false;
}
}
</script>
</head>
<body>
<a href="http://www.baidu.com" onclick="return del()">删除</a>
</body>
</html>
方法三:
<a href="javascript:if(confirm('确实要删除吗?'))location='jb51.php?id='">删除</a>
方法四:
<script type="text/javascript" language="javascript">
<!--
function confirmact()
{
if(confirm('确定要执行此操作吗?'))
{
return true;
}
return false;
}
//-->
</script>
<a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmact();">执行操作</a>
以上所述就是本文的全部内容了,希望大家能够喜欢。
更多javascript实现删除前弹出确认框。