Home  >  Article  >  Web Front-end  >  Confirm in js realizes the method of popping up the confirmation box before executing the operation

Confirm in js realizes the method of popping up the confirmation box before executing the operation

PHPz
PHPzOriginal
2016-05-16 16:33:022541browse

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( &#39;是否确定! &#39;)==false)return   false; ">点击确定</a>

If you want to call it simply, you can also do this

<a href="#" onclick= "return confirm(&#39;是否确定&#39;);">点击确定</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(&#39;确定要执行此操作吗?&#39;)) 
    { 
        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>


Statement:
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