No matter you have never learned java script before, this tutorial will take you to the Hall of java script to understand the charm of java script.
Everyone is here to be a fan of java scripts and have a certain understanding of java scripts. I will not introduce the history of java script. Let's learn it directly and use it.
Most people may think that java script runs on the client. Java script has two different runtime environments: javascript on the server side and javascript on the client side. In addition, javascript is also an object-based language.
As the first lesson, I just want to give you a simple understanding. There are not many things. There are three main aspects:
1. Add a java script to the page
2. Data Types of java scripts
3. Three basic dialog boxes of java script
I think everyone knows how to add a java script.
<Script language = "java script"> // This line is a java script mark, followed by a comment
Document. write ("java script displayed on the page") // display a sentence on the page
</Script>
/* This is also a comment,
But multiple rows.
*/
I don't want to elaborate on this today. If I leave it for the next lesson, I will take it as a homework. It is a java script that adapts to various environments.
. If the browser does not support java script, we should add something to prevent the browser from displaying the source code of java script.
The second is the most important one mentioned today. It is the data type of java script, which mainly includes the following basic types.
String)
Number)
Boolean)
A string is a series of characters. Including letters, numbers, and punctuation marks. Of course, it can also be Chinese characters. A little simpler
Indicates text information.
There are two types of numbers: integer numbers and floating-point numbers.
Integers include positive integers, zero and negative integers.
The numbers in java script can be written in decimal, octal, and hexadecimal notation. The method is as follows:
Decimal: 15 (write a number directly)
Octal: 017 (use zero as the guiding number)
Hexadecimal: 0xf (using 0x as the guiding number)
Floating-point numbers are also called real numbers. For convenience, they can also be expressed using scientific Notation:
1.13e1, 1.5e3 (equivalent to 1.5 multiplied by 10 to the power of 3)
The number range of java script is about 10 to the power of 308 to the power of 10.
There is also a special numeric value NaN (not a number) in java script. java script uses nan to represent this meaningless result.
Boolean values: true and false. in computer systems, 1 indicates true, and 0 indicates false.
Null is null, that is, nothing.
The undefined value is sometimes null, which may be a problem.
Special Character: Also called Escape Character. It is a special control character that cannot be displayed starting with a backslash.
\ B: Return
\ N: line feed
And so on.
Use of the alert () method:
<Script language = "java script">
Alert ("display warning dialog box on the page ");
</Script>
Alert () is a dialog box with a confirmation button generated by java script. The information in the brackets is displayed above.
Use of the confirm () method:
<Script language = "java script">
Confirm ("display confirmation dialog box on the page ");
</Script>
Confirm () is similar to alert (). The difference is that a Cancel button is added. True is returned by pressing OK, and false is returned by pressing cancel.
<Script language = "java script">
Var con;
Con = confirm ("do you like this tutorial? ");
If (con = true) alert ("like ");
Else alert ("dislike ");
</Script>
Use of the prompt () method:
<Script language = "java script">
Var name, age;
Name = prompt ("your name? ");
Alert (name );
Age = prompt ("How old? ");
Alert (age );
</Script>
It not only displays information, but also can input information.