Js-JavaScript-三种弹出提示框-alert-confirm-prompt-ai插件

博客介绍了JavaScript的三种交互框。alert提示框只有一个确定按钮;confirm确认框有Yes和No按钮,选Yes返回true,选No返回false;prompt输入框允许用户输入文本,取消返回null,确认返回对应文本。通过这三种方式可实现与程序的交互控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.alert-提示框

alert (message: string , title: string , errorIcon: Boolean )
Core JavaScript Classes
Displays an alert box
message: Data Type: string
The text to display
title (optional): Data Type: string
The title of the alert; ignored on the Macintosh
errorIcon (optional): Data Type: Boolean , Default Value: false
Display an Error icon; ignored on the Macintosh

弹出一个提示框,只有一个确定按钮。

alert("知了插件");

如下图所示:
在这里插入图片描述

2.confirm-确认框

confirm (message: string , noAsDefault: Boolean , title: string ): Boolean
Core JavaScript Classes
Displays an alert box with Yes and No buttons; returns true for Yes
message: Data Type: string
The text to display
noAsDefault (optional): Data Type: Boolean , Default Value: false
Set to true to set the No button as the default button
title (optional): Data Type: string
The title of the alert; ignored on the Macintosh

弹出一个确认框,选择Yes返回true,选择No放回false。

function test(){
    var rlt=confirm ("是否继续?", true, "提示");
    $.writeln (rlt);
}
test();

如下图所示:
在这里插入图片描述

3.prompt-输入框

prompt (prompt: string , default: string , title: string ): string
Core JavaScript Classes
Displays a dialog allowing the user to enter text
Returns null if the user cancelled the dialog, the text otherwise
prompt: Data Type: string
The text to display
default (optional): Data Type: string
The default text to preset the edit field with
title (optional): Data Type: string
The title of the dialog;

用户取消返回null,确认返回对应文本对象。

function test(){
    var rlt=prompt ("输入宽度:", "10", "提示");
    $.writeln (rlt);
}
test();

如下图所示:
在这里插入图片描述

4.总结

通过这三种方式,可以简单实现与程序的交互控制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值