alert提示框点确认不关闭
时间: 2024-03-28 10:42:33 浏览: 10
您可以使用以下代码来显示一个警告提示框,并且不让用户关闭它:
```
window.alert("这是一个警告提示框。");
```
用户只能点击“确定”按钮来关闭该警告提示框。如果您想要实现更高级的警告提示框,可以考虑使用一些 JavaScript 库,如 SweetAlert2、Bootstrap 等。
相关问题
C# Alert弹出框自动关闭实例
以下是一个 C# Alert 弹出框自动关闭的示例:
```csharp
using System;
using System.Windows.Forms;
using System.Threading;
public class Program
{
static void Main()
{
// 创建一个 Alert 弹出框
var alert = new Alert("这是一个自动关闭的弹出框", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// 启动一个新线程,等待 3 秒后关闭弹出框
new Thread(() =>
{
Thread.Sleep(3000);
alert.Invoke(new Action(() => alert.Close()));
}).Start();
// 显示 Alert 弹出框
alert.ShowDialog();
}
}
public class Alert : Form
{
public Alert(string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
Text = caption;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
StartPosition = FormStartPosition.CenterScreen;
Icon = SystemIcons.Information;
ControlBox = false;
var label = new Label
{
Text = message,
AutoSize = true,
Location = new System.Drawing.Point(10, 10)
};
Controls.Add(label);
var okButton = new Button
{
DialogResult = DialogResult.OK,
Text = "确定",
Location = new System.Drawing.Point(140, 60)
};
Controls.Add(okButton);
AcceptButton = okButton;
DialogResult = DialogResult.OK;
}
}
```
这个示例创建了一个 Alert 弹出框,并在启动一个新线程后等待 3 秒后自动关闭弹出框。你可以根据需要修改线程等待时间。
js 只有确认按钮的提示框
JS 只有确认按钮的提示框可以使用 `alert()` 方法来实现,它会弹出一个带有确认按钮的对话框,用于向用户显示一些信息。其语法如下:
```
alert(message);
```
其中,`message` 是要显示在对话框中的文本信息。
例如,下面的代码会在页面中弹出一个对话框,显示一条提示信息:
```
alert("操作成功!");
```
在上面的例子中,我们使用 `alert()` 方法弹出一个对话框,显示文本 "操作成功!"。用户只能点击确认按钮,关闭对话框。