Home > Web Front-end > JS Tutorial > body text

Detailed explanation of usage examples of confirm() in js confirmation box

不言
Release: 2018-05-02 10:15:46
Original
2663 people have browsed it

This article mainly explains the usage of js confirmation box confirm() with examples. It introduces three ways to use the javascript confirmation box. Interested friends can refer to it.

Let me introduce javascript to you first. There are three ways to use the confirmation box. The specific content is as follows

The first method: is very easy to use. The download address page can only be opened after confirmation. The principle is also relatively clear. Mainly used to confirm deletion of a single message.

<SCRIPT LANGUAGE=javascript> 
function del() { 
 var msg = "您真的确定要删除吗?\n\n请确认!"; 
 if (confirm(msg)==true){ 
  return true; 
 }else{ 
  return false; 
 } 
} 
</SCRIPT>
Copy after login

Calling method:

 <a href="del.php?id=123" onclick="javascript:return del()">删 除</a>
Copy after login

Second method: The principle is the same as above. JavaScript delete confirmation box

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

##Third method:Main Confirmation prompt for batch deletion

<input name="Submit" type="submit" class="inputedit" value="删除" 
 onclick="{if(confirm(&#39;确定纪录吗?&#39;)){
  this.document.formname.submit();
  return true;}return false;
 }"> 
<input name="按钮" type="button" ID="ok" onclick="{if(confirm(&#39;确定删除吗?&#39;)){
 window.location=&#39;Action.asp?Action=Del&
 TableName=Item&
 ID=<%=ID%>&#39;;
 return true;
}return false;}" value="删除栏目" />
Copy after login

Let me share with you another example:

js confirmation box confirm() code Example

Rendering:


confirm() confirmation box on the web page It is more commonly used in . Of course, some web pages with high aesthetic requirements may need to customize such a function. Let’s introduce the usage of the confirm() function of the window object. Let’s take a look at a code example, because there is nothing more complicated than this. Intuitive.


<!DOCTYPE html> 
<html> 
<head> 
<meta charset="gb2312"> 
<title>confirm()代码实例</title> 
<script type="text/javascript"> 
window.onload=function(){
 var bt=document.getElementById("bt");
 bt.onclick=function(){
  if(confirm("真的要删除吗?")){
   alert("点击了确认按钮");
  }
  else{
   alert("点击了取消按钮");
  }
 }
}
</script> 
</head> 
<body> 
<input type="button" id="bt" value="点击弹出确认框" />
</body> 
</html>
Copy after login

The above code is a simple example of confirm, which can clearly demonstrate the function of confirm(). Here is some summary:

1. The parameter in the confirm() function is the prompt of the confirmation box.
2. The return value of this function is Boolean. Click OK and the return value is true. Click Cancel and the return value is false.

Related recommendations:

Bootstrap custom confirm prompt effect sharing

Introduction to the use of confirm() method in JavaScript

The above is the detailed content of Detailed explanation of usage examples of confirm() in js confirmation box. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template