This article mainly introduces the method of confirm in js to pop up a confirmation box before performing an operation. It is a commonly used function when performing operations such as deletion. It is of great practical value. Friends in need can refer to it. The specific implementation method is as follows:
Now a confirmation prompt will pop up before deletion or other operations. We have many methods, the most basic one is to use the function confirm that comes with js.
The simplest usage is as follows:
Use confirm for mouse events
<a href="#" onclick= "if(confirm( '是否确定! ')==false)return false; ">点击确定</a>
If you want to call it simply, you can also do this
<a href="#" onclick= "return confirm('是否确定');">点击确定</a>
Click super If you click OK after linking, you will enter the address connected to the hyperlink. If you click Cancel, the hyperlink will not be executed, for example:
<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>
Usage:
If there is no connection, we can do this: onclick="return confirmAct();" Add code
Example:
<span onclick="return confirmAct();">点击我试一下</span>