Home Web Front-end JS Tutorial Javascript realizes the effect of confirming and canceling the prompt box_javascript skills

Javascript realizes the effect of confirming and canceling the prompt box_javascript skills

May 16, 2016 pm 03:50 PM
javascript Cancel Prompt box Sure

This effect is found on many web pages. When you click a button or other object, a prompt box will pop up. If you click OK, you will continue to execute the established program. If you click Cancel, you will cancel and continue execution. The code example is as follows:

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>确定和取消提示框</title>
<style type="text/css">
div
{
 width:150px;
 margin:0px auto;
}
a
{
 font-size:12px;
 color:blue;
}
</style>
<script type="text/javascript">
window.onload=function(){
 var mylink=document.getElementById("mytest");
 mylink.onclick=function(){
  if(confirm("确定要访问吗"))
  {
    return true;
  }
  else
  {
    return false;
  }
 }
}
</script>
</head>
<body>
 <div><a href="/" id="mytest">点击跳转</a></div>
</body>
</html>

Copy after login

In the above code, when you click on the link, a prompt box will pop up. If you click OK, you will visit the Ant Tribe homepage, otherwise you will not visit. The core of realizing this function is to use confirm(), and the parameter value is the text content of the prompt box. Here is a brief introduction to the principle of the above code:

1. When a link is clicked, the onclick event handler bound to the a element will be called.

2. In the event processing function, since confirm() will return true when the OK button is clicked, and false when the cancel button is clicked, the if statement will choose to execute the if statement or else statement based on the return value of confirm(). .

The above is the entire content of this article, I hope you all like it.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to cancel window overlay and cascading effects in Win11 How to cancel window overlay and cascading effects in Win11 Jan 10, 2024 pm 02:50 PM

The default window overlapping in win11 is very annoying, so many friends want to cancel the overlapping windows, but don’t know how to cancel it. In fact, we only need to use relevant software. How to cancel overlapping windows in win11 Method 1: Cancel through the taskbar 1. Win11 does not have its own cancellation function, so we need to download a "startallback" 2. After the download is completed, "unzip" the compressed package. After the decompression is completed, open folder, run the illustrated installation program to complete the installation. . 3. After the installation is completed, you need to open the "Control Panel" and then change the "View by" in the upper right corner to "Large Icons". 4. In this way, you can find "startallback", click to open it, and enter the "Tasks" on the left

How to cancel an order with Meituan How to cancel an order with Meituan Mar 07, 2024 pm 05:58 PM

When placing orders using Meituan, users can choose to cancel the orders they do not want. Many users do not know how to cancel Meituan orders. Users can click on the My page to enter the order to be received, select the order that needs to be canceled and click Cancel. How to cancel an order with Meituan 1. First, click on Meituan My Page to enter the order to be received. 2. Then click to enter the order that needs to be canceled. 3. Click Cancel Order. 4. Click OK to cancel the order. 5. Finally, select the reason for cancellation according to your personal situation and click Submit.

Tutorial to cancel win11 screen lock Tutorial to cancel win11 screen lock Dec 31, 2023 pm 12:29 PM

In order to protect the screen content or save power, we often turn on the screen saver, but find it very troublesome to re-enter the password lock every time after exiting the screen saver. So how to cancel the win11 screen lock? In fact, it can be turned off in the screen saver settings. How to cancel the win11 screen lock: 1. First, we right-click a blank space on the desktop and open "Personalization" 2. Then find and open the "Lock Screen Interface" on the right 3. Then open the "Screen Saver" in the relevant settings at the bottom 4. Finally, check "Show login screen on restore" and confirm to save to cancel the screen lock.

Detailed steps to cancel the ear symbol on WeChat Detailed steps to cancel the ear symbol on WeChat Mar 25, 2024 pm 05:01 PM

1. The ear symbol is the voice receiver mode. First, we open WeChat. 2. Click me in the lower right corner. 3. Click Settings. 4. Find the chat and click to enter. 5. Uncheck Use earpiece to play voice.

Where to cancel Mango TV automatic renewal? Where to cancel Mango TV automatic renewal? Feb 28, 2024 pm 10:16 PM

When many users experience Mango TV, a video software, they choose to become members in order to enjoy more film and television resources and more comprehensive services. In the process of using Mango TV membership services, some users will choose to turn on the automatic renewal function to enjoy the discounts to ensure that they will not miss any exciting content. However, when users no longer need membership services or want to change the payment method, canceling the automatic renewal function is a very important thing to protect the safety of property. How to cancel the automatic renewal service of Mango TV? Users who want to know Come and follow this article to learn more! How to cancel the automatic renewal of membership on Mango TV? 1. First enter [My] in the Mango TV mobile APP, and then select [VIP Membership]. 2. Then find [Tube

How to cancel automatic renewal on iQiyi How to cancel automatic renewal on iQiyi How to cancel automatic renewal on iQiyi How to cancel automatic renewal on iQiyi Feb 22, 2024 pm 04:46 PM

You can open the management automatic renewal function on the My Gold VIP Member interface to cancel. Tutorial Applicable Model: Huawei P50 System: HarmonyOS2.0 Version: iQiyi 12.1.0 Analysis 1 Open the iQiyi app on your phone, and then enter the My page. 2 Then click Gold VIP Membership at the top of my page, and then click Manage Automatic Renewal Options. 3. Click Cancel automatic renewal in the pop-up window. If you are not interested, continue to cancel. 4Finally confirm to turn off automatic renewal and click I understand, just reject it cruelly. Supplement: How to cancel the automatic renewal function of iQiyi on Apple mobile phone 1. Open the settings on the phone, and then click [AppleID] at the top of the settings interface. 2Click [Subscribe] on the AppleID interface to select

Operation steps for canceling subscription payment on WeChat Operation steps for canceling subscription payment on WeChat Mar 26, 2024 pm 08:21 PM

1. Click the [iTunesStore and AppStore] option in the phone settings. 2. Click [View AppleID], and then enter the login password. 3. Enter the [Account Settings] interface and click [Payment Information]. 4. Check the payment method as [None] and click [Finish]. After completion, return to the WeChat interface. At this time, you will receive the [Successful Cancellation Notification] message, and WeChat will no longer automatically deduct fees.

How to remove the firewall logo on the Win10 desktop icon? How to remove the firewall logo on the Win10 desktop icon? Jan 01, 2024 pm 12:21 PM

Many friends who use win10 system find that there is a firewall logo on the icon on the computer desktop. What is going on? This makes many friends with obsessive-compulsive disorder particularly uncomfortable. In fact, we only need to open the control panel and click " It can be solved by changing "Change User Account Control Settings". Let's take a look at the specific tutorial. How to cancel the firewall logo on the desktop icon in Windows 10 1. First, right-click the Start menu button next to the computer startup screen, and then select the Control Panel function from the pop-up menu. 2. Then select the "User Account" option and select the "Change User Account Control Settings" item from the new interface that appears. 3. After adjusting the slider in the window to the bottom, click Confirm to exit.

See all articles