This article describes the method of pop-up confirm box before executing operations in JS. Share it for your reference. The specific implementation method is as follows:
Now a confirmation prompt pops up before deleting or other operations. We have many methods. The most basic one is to use the function confirm, which comes with js.
The simplest usage is as follows:
Use confirm for mouse events
Copy the code code as follows: <a href="#" onclick= "if(confirm( 'Are you sure! ')==false)return false; ">Click OK</a>
If you want to call it simply, it can be the same
Copy the code as follows: <a href="#" onclick= "return confirm('Is it OK');">Click OK</a>
After clicking on the hyperlink, if you click OK, you will enter the address connected to the hyperlink. If you click Cancel, do not execute the hyperlink
example.
Copy the code as follows:<script type="text/javascript" language="javascript">
<!--
function confirmAct()
{
if(confirm('Are you sure you want to do this?'))
{
return true;
}
return false;
}
//-->
</script>
<a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmAct();">Perform an action</a>
How to use:
If it is not connected, we can add the code, for example: onclick="return confirmAct();"
example
Copy the code as follows: <span onclick="return confirmAct();">Click me to try</span>
I hope that the description in this article will be helpful to everyone's web programming based on javascript.