Home > Web Front-end > JS Tutorial > body text

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

PHPz
Release: 2018-09-30 14:05:27
Original
1595 people have browsed it

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( &#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 like: onclick="return confirmAct();" Add code, for example:

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

The above is the entire content of this chapter. For more related tutorials, please visit JavaScript Video Tutorial!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!