This article mainly introduces the confirm method 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 who need it can refer to this article
The example describes the method of confirm in js to pop up the confirmation box before executing the operation. Share it with everyone for your reference. The specific implementation method is as follows: Now a confirmation prompt pops 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 like: onclick="return confirmAct();" Add code, for example:
<span onclick="return confirmAct();">点击我试一下</span>
The above is the entire content of this chapter. For more related tutorials, please visit JavaScript Video Tutorial!