Rewrite the behavior of window.confirm in javascript_javascript tips
The window.confirm method in javascript is very useful. It can pop up a confirmation dialog box
The reason why we pop up this dialog box may be because the operation is very dangerous, so the user is required to confirm. But if "OK" is selected by default, this principle may be violated.
In addition, the buttons of the confirm dialog box are fixed at "OK" and "Cancel". It may not be very intuitive sometimes.
So, you can consider using msgbox in vbscript to rewrite this behavior. The following is an example
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<script> <br>function deleteConfirm(msg) <br>{ <br> function window.confirm(str) <br>{ <br>str= str.replace(/'/g, "'& chr(39) &'").replace(/rn/g, "'& VBCrLf &' "); <br>execScript("n = msgbox('" str "', 289, 'Delete box')", "vbscript"); <br>return(n == 1); <br>} <br>return window.confirm(msg); <br>} <br></script>
For specific details of the msgbox method, you can also refer to the following introduction
The MsgBox function
displays a message in the dialog box, waits for the user to click the button, and returns a value indicating that the user has clicked the button. button to click.
MsgBox(prompt[, buttons][, title][, helpfile, context])
Parameters
prompt
A string expression that is displayed as a message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the character width used. If the prompt contains multiple lines, you can use carriage returns (Chr(13)), line feeds (Chr(10)), or a combination of carriage returns and line feeds (Chr(13) & Chr(10)) between the lines. ) separates the lines.
Buttons
Numerical expression, which is the sum of the values that specify the number and type of buttons to be displayed, the icon style used, the identity of the default button, and the message box style. See the Settings section for values. If omitted, the default value for buttons is 0.
Title
A string expression displayed in the title bar of the dialog box. If title is omitted, the application's name is displayed in the title bar.
Helpfile
String expression that identifies the help file that provides context-sensitive help for the dialog box. If helpfile is provided, context must be provided. Not available on 16-bit system platforms.
Context
A numeric expression that identifies the context number assigned to a help topic by the author of the help file. If context is provided, helpfile must be provided. Not available on 16-bit system platforms.
Settings The
buttons parameter can have the following values:
Constant | Value | Description |
---|---|---|
vbOKOnly | 0 | Only the OK button will be displayed. |
vbOKCancel | 1 | Displays the OK and Cancel buttons. |
vbAbortRetryIgnore | 2 | Shows the Abandon, Retry and Ignore buttons. |
vbYesNoCancel | 3 | Shows Yes, No and Cancel buttons. |
vbYesNo | 4 | Displays Yes and No buttons. |
vbRetryCancel | 5 | Displays the Retry and Cancel buttons. |
vbCritical | 16 | Display the critical information icon. |
vbQuestion | 32 | Display the Warning Query icon. |
vbExclamation | 48 | Display Warning Message icon. |
vbInformation | 64 | Displays the Information message icon. |
vbDefaultButton1 | 0 | The first button is the default button. |
vbDefaultButton2 | 256 | The second button is the default button. |
vbDefaultButton3 | 512 | The third button is the default button. |
vbDefaultButton4 | 768 | The fourth button is the default button. |
vbApplicationModal | 0 | Application Mode: The user must respond to the message box to continue working in the current application. |
vbSystemModal | 4096 | 系统模式:在用户响应消息框前,所有应用程序都被挂起。 |
第一组值 (0 - 5) 用于描述对话框中显示的按钮类型与数目;第二组值 (16, 32, 48, 64) 用于描述图标的样式;第三组值 (0, 256, 512) 用于确定默认按钮;而第四组值 (0, 4096) 则决定消息框的样式。在将这些数字相加以生成 buttons 参数值时,只能从每组值中取用一个数字。
返回值
MsgBox 函数有以下返回值:
常数 | 值 | 按钮 |
---|---|---|
vbOK | 1 | 确定 |
vbCancel | 2 | 取消 |
vbAbort | 3 | 放弃 |
vbRetry | 4 | 重试 |
vbIgnore | 5 | 忽略 |
vbYes | 6 | 是 |
vbNo | 7 | 否 |
설명
helpfile과 context가 모두 제공되는 경우 사용자는 F1 키를 눌러 해당 context에 해당하는 도움말 항목을 볼 수 있습니다.
대화 상자에 취소 버튼이 표시되는 경우 ESC 키를 누르면 취소를 클릭하는 것과 같은 효과가 있습니다. 대화 상자에 도움말 버튼이 포함된 경우 대화 상자에 상황에 맞는 도움말이 제공됩니다. 그러나 다른 버튼을 클릭할 때까지 아무 값도 반환되지 않습니다.
Microsoft Internet Explorer가 MsgBox 기능을 사용할 때 모든 대화 상자의 제목에는 표준 대화 상자와 구별하기 위해 항상 "VBScript"가 포함됩니다.
다음 예는 MsgBox 함수의 사용법을 보여줍니다.
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox 예제")
' MyVar에는 클릭한 버튼에 따라 1 또는 2가 포함됩니다.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
