Home > Web Front-end > JS Tutorial > 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
Release: 2018-09-30 14:19:54
Original
2601 people have browsed it

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>
Copy after login

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

<a href="#" onclick= "return confirm(&#39;是否确定&#39;);">点击确定</a>
Copy after login

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>
Copy after login
<a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmAct();">执行操作</a>
Copy after login

Usage:

If there is no connection, we can do this: onclick="return confirmAct();" Add code
Example:

<span onclick="return confirmAct();">点击我试一下</span>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template