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>
Calling method:
<a href="del.php?id=123" onclick="javascript:return del()">删 除</a>
Second method: The principle is the same as above. JavaScript delete confirmation box
<a href="javascript:if(confirm('确实要删除吗?'))location='jb51.php?id='">删除</a>
##Third method:Main Confirmation prompt for batch deletion
<input name="Submit" type="submit" class="inputedit" value="删除" onclick="{if(confirm('确定纪录吗?')){ this.document.formname.submit(); return true;}return false; }"> <input name="按钮" type="button" ID="ok" onclick="{if(confirm('确定删除吗?')){ window.location='Action.asp?Action=Del& TableName=Item& ID=<%=ID%>'; return true; }return false;}" value="删除栏目" />
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>
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.
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!