Home  >  Article  >  Web Front-end  >  Javascript implements pop-up confirmation box before deletion

Javascript implements pop-up confirmation box before deletion

高洛峰
高洛峰Original
2016-12-17 13:49:271384browse

Requirement: When the user clicks the delete button, a confirmation box will pop up. If the user clicks "OK", the deletion operation will be performed. Otherwise, the

JS code

function del() {
var msg = "您真的确定要删除吗?\n\n请确认!";
if (confirm(msg)==true){
return true;
}else{
return false;
}
}

html code

<a href="" onclick="javascript:return del();">删除</a>

Method 2:

<!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>

Method 3:

<a href="javascript:if(confirm(&#39;确实要删除吗?&#39;))location=&#39;jb51.php?id=&#39;">删除</a>
will not be executed

Method 4:

<script type="text/javascript" language="javascript"> 
<!-- 
function confirmAct() 
{ 
  if(confirm(&#39;确定要执行此操作吗?&#39;)) 
  { 
    return true; 
  } 
  return false; 
} 
//-->
</script> 
  
<a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmAct();">执行操作</a>

The above is the entire content of this article, I hope you all like it.

For more javascript implementation of pop-up confirmation box before deletion related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn