JavaScript Basics (i)

Source: Internet
Author: User

Javascript
First, what is JavaScript?
Script Description Language, Web Interactive effects, plainly, is the implementation of HTML can not achieve the effect. (JavaScript is an object-based, event-driven, simple scripting language embedded in an HTML document that is interpreted and executed by the browser, creating a dynamic display on a Web page and interacting with the user.) )


Html:
Hypertext Markup Language
Css:
Web page Style
Javascript:
Web Interactive effects

Second, why use JavaScript?
Solve the problems we can not solve now, for example, the form of timely verification, picture carousel ...

Third, the syntax:
<script type= "Text/javascript" >

</script>

1, document.write ("hello!!");
On the Web page output hello!!, in fact this equivalent is: System.out.print ();

2, the Process Control in Java, the same use in JavaScript.

3. Three kinds of pop-up windows
A, alert ();----used more, test
Warning pop-up window, only content and OK button

B, confirm ();
Prompt window, with content, OK and Cancel buttons, click OK, return True, click Cancel
returns false;

C, prompt ();
User Input window, with prompt, input box, OK and Cancel button, click OK, return
The contents of the text box, click Cancel, return null

Four, the code demonstration case:

1, output 1000 times in the page good study day up

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>4<title> second question </title>5<script type= "Text/javascript" >6  for(vari=1;i<=1000;i++){7document.write ("+i+") "+" good study, every day fooled!!! <br/> ");8 }9</script>Ten One  A<body> -</body> - the  -Output 1000 times in the page good study day

2. Achieve Calculator effect

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>4<title> Untitled Document </title>5<script type= "Text/javascript" >6 varNUM1 =window.prompt ("1, addition; 2, subtraction; 3, multiplication; 4, Division;"));7 varNum2 =window.prompt ("Please enter first number");8 varnum3 =window.prompt ("Please enter a second number");9 varA =parseint (NUM1);Ten varb =parseint (num2); One varc =parseint (num3); A vard = 0; - Switch(a) { -      Case1: theD = B +C; -      Break; -      Case2: -D = bC; +      Break; -      Case3: +D = b*C; A      Break; at      Case4: -D = b/c; -      Break; - } -document.write ("result is:" +d); -</script> in -  to<body> +</body> - the  *Implementing the Calculator effect

3. Pop-up window demo case

12<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>3<title> Untitled Document </title>45<script type= "Text/javascript" >6     //alert ("123");//Warning pop-up window7     //Window.alert ("321");8     //var q = window.confirm ("456");//with OK and cancel popup, click OK, return True, click Cancel, return False9     //document.write (q);Ten     //var a = window.prompt ("Please Enter Name:", "small Black");//can implement user input pop-up window, click OK, return the contents of the input box, click Cancel, return null One     //document.write (a); A     //var t = ""; -     //While (t!= "small Black") { -     //t = window.prompt ("Please enter Name:"); the     //} -     varnum = window.prompt ("Please enter a value of 1-9"); -     if(num>1&&num<=9){ -          for(vari = 1;i<=num;i++){ +              for(varj = 1;j<=i;j++){ -document.write ("*"); +             } Adocument.write ("<br/>"); at         } -}Else{ -Alert ("Please enter correctly"); -     } -</script> -<body> in</body> - to  +Pop-up window demo case

4. Comprehensive demonstration Cases

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>4<title> Untitled Document </title>5 67<script type= "Text/javascript" >8      for(varI =1;i<=4;i++){9          for(varK = 3;k>=i;k--){Tendocument.write ("&nbsp;&nbsp;"); One         } A          for(varj = 1;j<=2*i-1;j++){ -document.write ("*"); -         } thedocument.write ("<br/>"); -     } -      for(vari = 1;i<=3;i++){ -          for(varK = 0;k<i;k++){ +document.write ("&nbsp;&nbsp;"); -         } +          for(varK = 3;k>=i;k--){ Adocument.write ("*"); at         } -          for(varK = 3;k>i;k--){ -document.write ("*"); -         } -document.write ("<br/>"); -     } indocument.write ("-----------------------I am the split line-the cumulative value of output 1-100, skipping 3 digits--------------<br/>"); -     varsum = 0; to      for(vari = 1;i<=100;i++){ +         if(i%10!=3){ -sum = sum +i; the         } *     } $document.write ("sum=" +sum);Panax Notoginsengdocument.write ("<br/>-----------------------I'm a split line-chicken and rabbit cage--------------<br/>"); -      for(varJi = 0;ji<=24;ji++){ the         varTu = 24-ji; +         if(ji*2+tu*4==60){ Adocument.write ("Chickens have" +ji+ "only, rabbits have" +tu); the         } +     } -document.write ("<br/>-----------------------I am the dividing line-classical question--------------<br/>"); $     varStart=1; $     varNext=1; -      for(vari=3;i<13;i++){ -         vartemp=start+Next; thestart=Next; -next=temp;Wuyi          the          - Document.writeln (next); Wu         } -</script> About<body> $</body> -  -Comprehensive Demo case

JavaScript Basics (i)

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.