Brief introduction:
1. What is JavaScript?
It is a scripting language that makes HTML pages more dynamic and interactive, requires a host file, and its host file is an HTML file.
JavaScript is the WEB's programming language.
All modern HTML pages use JavaScript.
<script> tags are used to define client-side scripting, such as JavaScript.
The <script> element can contain either a script statement or an external script file via the SRC attribute.
JavaScript is most commonly used for picture operations, form validation, and dynamic content updates.
2, the use of JS:
It is commonly used in the HTML location has three kinds: 1, head inside 2, body inside 3,
The code must be written in <script> code </script>. (or <script language= "JavaScript" > Code </script> or <script type= "Text/javascript" ></script>
3. Three common dialog boxes
Alert ("")--warning dialog box, function is to pop up a warning dialog box
For example:
alert (" there is an error! ")</script>
It has only a "OK" button and a "close" button in the upper-right corner for a pop-up warning.
Confirm ("")--OK dialog box, function is to pop up a selection of OK dialog box, click OK, it returns ture, click Cancel return False, the available variables to receive
For example
var a=confirm (" Are you sure you want to quit?" ") alert (a)</script>
Click OK to return to Ture
return false after clicking Cancel
Prompt ("Prompt content", "Default display Content") function is to pop up a dialog box to enter the content
For example
prompt (" Please enter a positive integer:"," can only be a number!") ")</script>
Syntax: basically consistent with C #
1. Basic Data type
String, Decimal, Integer, Date type, Boolean type, and so on
2. Variables
are universal type VAR (universal variable), can be stored casually other types of values, can be used directly, not defined, but the customary definition, for example: Var a=5; or var a= "Baidu", or Var a=false;
3. Operators
Math operators: + 、-、 *,/
Relational operator: = = = = >= <=
Logical operator:&& | | !
Other operators: + = = *=/=?:
4. Statements
Generally divided into sequential, branching, and cyclic statements, with C #
5. Arrays (collections with C #)
The definition of the array: var array = new Array (), its length is dynamic, and it can put any type of element.
Assignment of the array: array[0]=3; Array[1]= "hello!";
The length of the array: Array.Length;, the number of array elements
Method: Array.Sort () sorts the array, sorts by the first character, Array.revers () flips the array
6. Functions
Function four elements: name, input, return value, processing (function body)
Define functions: Function Add () {} Add is the function name, as in C # functions There are four forms, the return value can be var type, can return a value
function does not call is not executed
7. Type Conversion
Divided into auto-convert and cast, general cast
Other types converted to integers: parseint ();
Other types converted to decimals: Parssfloat ();
The other is to determine whether it is a valid data type: IsNaN () J; (is not a number is a digit), is a number then returns false, not a number words return ture
For example
var A; var s=prompt (" Please enter a positive integer:"," can only be a number!") "= IsNaN (s); alert (a)</script>
7, $ ("id") equivalent to document.getElementById ("id")
Learn HTML Basics-JAVASCRITP Introduction and syntax