w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS Popup Boxes
In JavaScript we can create three kinds of popup boxes: Alert box, Confirm box, and Prompt box.
ÔÚJSÀïÎÒÃÇ¿ÉÒÔ½¨Á¢ÈýÖÖ²»Í¬Ñù×ÓµÄpopup boxesµ¯³ö¿ò£º¾¯Ê¾¿ò£¬È·ÈÏ¿ò£¬ÐÅÏ¢¿ò
Alert box[¾¯Ê¾¿ò]
Alert box with line breaks[»»Ðеľ¯¸æ¿ò]
Confirm box[È·ÈÏ¿ò]
Prompt 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")
|
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")
|
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")
|