Client-side scripting language JavaScript

Source: Internet
Author: User

2015.11.27 Client-side scripting language JavaScript.

(The reason for calling this name.) Want to marrying up, hope to become as common as him. The relationship between names is similar to Lei Feng and Leifeng Pagoda, and the relationship between Pakistan and Kaspersky, Socrates and Glashütte. Adi Wang and Adidas) Master Kang and Congobo

is also a part of javaweb ,javascript is now very powerful. It is mainly used in B /s part of the Browser client part.

1, JavaScript language, in the run time is not required server, only the browser can be interpreted js code.

2. Scripting language: It cannot run independently on the browser side, it must be attached to the HTML page.

3, JS or a weak type of language,var i=2,i = "2342";//int i=9;

4. Object-Oriented development language

5, the role of JS:

1) allows programs and users to interact without having to go through the server

2) dynamically change the content of the page (dynamically manipulate html tags, even styles)

3) format validation of the form for data

6, JS embedded in the HTML page in the way:

1) in-page

A. row level

B.head .

2) External files

7. Arrays

1) The array element in JS can be any type (but it is recommended to use only one type), and data traversal is more convenient.

2) The length of the array in JS can be infinitely increased.

Summary:javascript Concepts, embedding methods, definition and use of variables, method definitions and use of JS built-in objects and methods. How to get the value of the input box includes the ID name innerhtml Array.

Job:1, write a calculator. (eval ())

The revelation of case one, three kinds of ways to introduce JS .

External introduction and script output written in head can only survive one? The first existence will be left?

Case two: You can get the document objectin the script,document.write("") , the statement that takes precedence over the HTML is first output.

Case three : in Java:int a,b,c=3; each of the three variables is int type of.

But in JavaScript ,var a,b,c=3; Three variables are not necessarily the same type, and their type is determined after the assignment. Can you change the type after it is OK? And can be changed after the type is determined.

<script type= "Text/javascript" >    var a,b,c=3;    alert (c);    c= "I am li Fei";    alert (c); </script>

The result in the browser is: first output 3, in the output of a "I am Li Fei."

In JavaScript, html is viewed as a document object,HTML Each of these tags is considered a node object. such as <body><table>

Case FOUR: The resulting data from the page is considered to be of type String .

<script type= "Text/javascript" >    var price = prompt ("Please enter a number:");    price =price+100;    alert (price);    price +=100;    alert (price);    Price =parseint (price) +100;    alert (price); </script>

The results of the output are 100100,100100100,100100200 respectively.

Case FIVE:

<script type= "Text/javascript" >//Global Variables    varNumber1=1; //Global Variablesnumber2=2; functionfunction1 () {alert (Number1+number2); }    functionfunction2 () {//Local Variables        varNumber3=4; //Discounted Global VariablesNumber4=8; Alert (Number1+number2+number3+number4); }//alert (number1+number2+number3+number4);function1 (); Function2 ();</script>

All of this is understandable in addition to the discounted global variables. Here is a description of some of the features that are different from Java. Only when function is called,number4 is globally reachable. Otherwise,number4 can never be used. As a Javaer It is not advisable to use this. Variables have to be declared. The unification is written in the form of the number 1 and the number 3.

After the comment is canceled, the result is not seen. Because. will report that Number3 is undefined.

How to view:

When you open the browser, press F12 to view it. The default entry Elements requires a manual switch to the console panel.

Case SIX:

var function1= function () {            alert ("We assign the definition of a function to a variable called function1. Therefore, Function1 is the function name of this function. ");    }    Function1 ();          for (i=0;i<5;i++) {            }    alert (i);

In the loop do not tangle, there is no definition of a way to change I into a partial. But you can cheat yourself to write var i=0. There is one sentence that must give the initial value.

Case Seven:

Forget the code First:

<script type= "Text/javascript" >    function  function1 () {        var number1 = document.getElementById ("Number1"). Value;         var number2 = document.getElementById ("number2"). Value;         var result=parseint (number1) +parseint (number2);        alert (result);        } </script>

This will forget two things, one is number1 Remember to add double quotation marks, and then remember add . Value.

This error is reported because there is no "".

is not a number because there is no value added.

There is one more bug. In the spring with the fall, you can not see this javaScript Reminder ( There is a reminder box inside, but there is no content in the box.) ), but in Chrome You can intercept the complete reminder.

Not all associations are going to give. Some of the content is true, but not surprisingly. Perhaps this dreamwaver after all only dozens of trillion reason. For example, in innerText and InnerHTML This attribute, only the latter one, the previous one does not.

Maybe parsedouble did not, but parsefloat is.

If you want to add a color to the output, you need the following:

 <script type= "Text/javascript" > function   Function1 () { var  number1 = Document.gete        Lementbyid ("Number1" ). Value;  var  number2 = document.getElementById ("Number2"        ). Value;  var  result=parseint (number1) +            Parsefloat (NUMBER2); document.getElementById ( "Number3"). Innerhtml= "<font color= ' Red ' >" +result+ "</font>" ; }  </script>

The easy-to-forget point is:document.getElementById ("Number3"). Innerhtml= after the group to spell, and remember to add "" to the group to spell.

Case 8: If you want to commit something, there are operand 1, operator 1, operand 2, and commit button, four values, Why not add a form?

The array is better understood, the teacher was also speaking more clearly, here will not write.

Calculator, not the General Assembly do AH.

What is JavaScript?

JavaScript is a scripting language that provides user interaction, dynamic change of content, and data validation.

The main functions are:1, data validation 2, Web page effects 3,js is a scripting language, so its code has become js script.

Data type:

Client-side scripting language JavaScript

Related Article

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.