Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1480749
  • 博文数量: 187
  • 博客积分: 10375
  • 博客等级: 上将
  • 技术积分: 3127
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-07 10:58
文章分类

全部博文(187)

文章存档

2013年(1)

2012年(8)

2011年(28)

2010年(36)

2009年(47)

2008年(67)

我的朋友

分类:

2010-09-16 17:47:16

**************************************
alert()
confirm()
prompt()
**************************************
alert()
The simplest to direct output to a dialog box is to use the alert() method.
alert("Click Ok to continue.");
NOTICE: that the alert() method doesn’t have an object name in front of it. This is because the alert() method is part of the window Object. As the top-level object in the Navigator Object Hierarchy, the window Object is assumed when it isn’t specified.
The script alert("Click Ok to continue."); and HTML holding the script will not continue or execute until the user clicks the OK button.
Generally, the alert() method is used for exactly that – to warn the user or alert him or her to something. Examples of this type of use include:
Incorrect information in a form
An invalid result from a calculation
A warning that a service is not available on a given date
Nonetheless, the alert() method can still be used for friendlier messages.
NOTICE: that Netscape alert boxes include the phrase " [JavaScript Application]" in the title bar of the alert while IE has "Microsoft Internet Explorerin the title bar of the alert. Both have yellow triangles to "alert" you. This done in order to distinguish them form those generated by the operating system or the browser. This done for security reasons so that malicious programs cannot trick users into doing things they don’t want to do.
OR
   The alert dialog box is used  to display an alert message to the user.
prompt()
The alert() method still doesn't enable you to interact with the user. The addition of the OK button provides you with some control over the timing of events, but it still cannot be used to generate any dynamic output or customize output based on user input.
The simplest way to interact with the user is with the prompt() method. The user needs to fill in the field and then click OK.
prompt("Enter Your Name:", "Name");
Note 1: you are providing two "arguments" to the method in the parenthesis. The prompt() method "requires two pieces of information". The first is text to be displayed, and the second is the default data in the entry field.
Note 2: In JavaScript, when a method requires more than one argument, they are separated by commas.
   The prompt() method dialog box allows the user the opportunity to enter information.  It takes two parameters; a message and a default string for the text entry field.
With function code:
NOTE: What happens when you press Cancel? The value null is returned.
confirm()
Confirm displays a dialog box with two buttons: OK and Cancel. If the user clicks on OK the window method confirm() will return true. If the user clicks on the Cancel button confirm() returns false.
   The confirm dialog box returns a Boolean value based on the user's selection.
With function code:
NOTE: response will be:
true if OK is pressed
false if Cancel is pressed
 
阅读(1207) | 评论(0) | 转发(0) |
0

上一篇:Oracle Merge Into

下一篇:JavaScript打印页面

给主人留下些什么吧!~~