Examples of JavaScript three pop-up boxes (Alert,confirm and prompt) __java

Source: Internet
Author: User
Warning (alert)

Did you ever get into a situation like this when you visit a website? "Boom", a small window appears in front of you, with a piece of warning text written, or other information. If you don't click OK, you won't be able to do anything with the page. Yes, this little "boom" window is alert.

The following code is an instance of using alert.

<script type= "Text/javascript" >
     alert ("I am a rookie I am afraid of who");
</script>

My personal view is to use alert as little as possible and it is unfriendly. It may even make some parties think your site is dangerous. Confirmation (confirm)

A confirmation box is used to let the user choose whether a problem is realistic.

Said Yes or No. Quick answer. ”

If you want to express such meaning, then confirm is more suitable. Look at the following code: we use confirm ("Are you a rookie?"). To ask the visitor, variable R saves the visitor's response, and it can only have two values: TRUE or FALSE. Yes, it's a Boolean value. The statement behind confirm is a different response to our visitors ' answers.

<script type= "Text/javascript" >
     var r=confirm ("Are you a rookie?");
     if (r==true)
     {
     document.write ("Same as");
     }
     else
     {
     document.write ("admire admire");
     }
</script>
questions (Prompt)

Prompt is similar to confirm, but it allows visitors to enter the answer at random. Let's revise the example of the previous switch, and we'll make a different evaluation based on the score, but the procedure is not complete, it doesn't ask us for a score, it's supposed to be 65 points. It's not fair. Now I can use prompt to ask visitors questions, use score to store user input answers, and the rest is done by the switch behind.

<script type= "Text/javascript" >
 function Judge () {
 var score;//fractional
 var degree;//fractional rank
 score = Prompt ("What's Your score?") ")
 if (Score >) {
 degree = ' fool me. 100 cent full. ';
 }
 else{
 switch (parseint (SCORE/10)) {case
 0: Case
 1: Case
 2: Case
 3: Case
 4: Case
 5:< C15/>degree = "Congratulations, hang up again." ";
 break;
 Case 6:
 degree = "barely pass";
 break;
 Case 7:
 degree = "do, make up" break
 ;
 Case 8:
 degree = "8 wrong, 8 wrong";
 break;
 Case 9: Case
 Ten:
 degree = "Master Master, admire admire";
 } End of Switch
 }//end of Else
 alert (degree);
 </script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.