01 of JavaScript

Source: Internet
Author: User

JavaScript can implement validation forms. Make special effects and other functions, JavaScript is mainly for the purpose of three points:

1 Client Form Validation
2 page Dynamic effects
3 The basis of jquery
JavaScript is a descriptive language and a scripting language that is Object-and event-driven and has security capabilities.
Together with HTML, he connects to multiple objects in a Web page, interacting with the customer, whether on the client or server side,
JS applications are downloaded to the browser client to perform, reducing the burden on the server.
JavaScript is primarily used to add interactive behavior to HTML pages.
JavaScript is a scripting language, and syntax is similar to java.
JavaScript is typically used to write client-side scripts.
JavaScript is an interpreted language that performs edge interpretation.
JavaScript includes ECMAScript BOM DOM
The basic structure of JavaScript:

<script type= "Text/javascript" >
JavaScript statements
</script>

Type is the language category for which the <script> tag's properties are used to specify the text; text/javascript
How to refer to JavaScript in a Web page:
1. Internal JavaScript files (for less code)

<body>
<script type= "Text/javascript" >
document.write ("Beginner JavaScript")

</script>
</body>
2. External JavaScript files
External files can be reused on multiple pages. External JavaScript files are written into an external file with JavaScript code, *.js as an extension
Save, and then write the address of the file to the SRC attribute in the <script> tag.

3. Directly in the HTML tag
The code is very small and only used for the current label, but this approach adds code, so this approach is rarely used in real-world development.
document.write (); Output statement
<input name= "bto" type= "buttom" value= "Message popup box" onclick= "Javascript:alert (' Hello ');" /> Message Popup dialog box Hello
Alert () function: POPs up a dialog box to the page

Declaration and assignment of variables
var valid variable name
var width=20;
var x,y,z=10;
JavaScript is strictly case-sensitive

Because JavaScript is a weakly typed language, allowing the system to be declared without declaring it is automatically declared.
X=88;//does not declare direct use
Declaration data type not required before declaration
Data type: undefined (undefined type)
Null (NULL type) (return value is Object)
Number (numeric type)
String (String type)
Boolean (Boolean type)
typeof (variable or value) determines which data type to belong to
The return result is object if the variable is a null type or is a reference type, such as an object, function, array
Method of the String object:
where IndexOf (Str,index) first appeared
The character at the CharAt (index) subscript
toLowerCase () Converts a string to lowercase
toUpperCase () Converts a string to uppercase
SUBSTRING (INDEX1,INDEX2) ring out characters according to subscript
Split (str) splits a string by character

Create an array
var array name =new array (size);
Assign value
var fruit=new Array ("1", "2", "3", "4", "5");//[]
You can also assign values like this
var fruit=new Array (4);
fruit[0]= "1";
fruit[1]= "2";
fruit[2]= "3";
Fruit[3]= "4";
fruit[4]= "5";

An array is an object of JavaScript, and he has a set of properties and methods:
Properties:. length
Method: Join (delimiter-) places all elements of an array into a string separated by delimiters. 1-2-3-4-5
Sort () Sorting arrays
Push () adds one or more elements to the end of the array

= = = identical! = = Not identical

Input/Output
Alert ("hint message") output
Prompt ("What do you Like", "Answer input box default information");
var color=prompt ("What color do you like", "pink");
alert (color);

Common system functions
A function that converts a non-numeric primitive value to a number
parseint ("string"); integer
Parsefloat ("string"); floating-point number
Check whether a non-numeric function
IsNaN (x); true/false

Custom functions
Function name (parameter 1, parameter 2, Parameter 3 ...) ){

[Return value]
}
function keyword
Calling functions
Event name = "function name ()";


Call <input name = "bto" type= "button" value= "Please enter the number of times displayed"
onclick = "Study (Prompt (' Please enter the number of displays ')"/>
Onclick=study (8); " />

01 of JavaScript

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.