In JavaScript we can create three kinds of popup boxes: Alert box, Confirm box, and Prompt box.
在JS里我们可以建立三种不同样子的popup boxes弹出框:警示框,确认框,信息框
Examples
例子
Alert box[警示框]
Alert box with line breaks[换行的警告框]
Confirm box[换行的警告框]
Prompt box[信息框(可输入参数)]
Alert Box
警示框
An alert box is often used if you want to make sure information comes through to the user.
如果你想保证让用户得到信息就使用警示框
When an alert box pops up, the user will have to click "OK" to proceed.
当警示框弹出,用户必须按“OK”来继续
Syntax:
语法:
alert("sometext") |
Confirm Box
确认框
A confirm box is often used if you want the user to verify or accept something.
确认框用来让用户核实或是接受一些信息。
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
当信息框弹出,用户必须按“OK”或者“Cancel”来继续
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
如果用户按"OK"就返回真,按"取消"就返回假
Syntax:
语法:
confirm("sometext") |
Prompt Box
信息框
A prompt box is often used if you want the user to input a value before entering a page.
信息框用来让用户在进入页面前输入值。
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.
当信息框弹出,用户将在输入值后按“OK”或“Canel”来继续(下面的操作)
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
按“OK”就会返回输入的值,按“取消”就会返回空值
Syntax:
语法:
prompt("sometext","defaultvalue") |