A brief summary of _javascript skills in JavaScript

Source: Internet
Author: User
Tags function definition numeric value tag name

The script in 1.HTML must be located between the <script> and </script> tags.

Scripts can be placed in the <body> and

2. If you need to access an HTML element from JavaScript, you can use the document.getElementById (ID) method

3. You can write content to HTML documents, including tags, via document.write (). Note that if document.write () is executed after the document has been loaded, the entire HTML document will be overwritten

4.JS comments through//and/**/two ways

5. Variable through VAR declaration, because JS is a weak type language, you can not specify the variable type.

var x=1  //number

var x= "a"//String

var x=true  //boolean

var x  //x No value, undefined

6. Functions use function definition

Functions function name () {

function body;

}

7.var num=new Number ()//Declare a number object

Number.MAX_VALUE Maximum Value
Number.min_value Minimum value
Number.NaN Special non-numeric values
Number.negative_infinity Negative Infinity
Number.POSITIVE_INFINITY is Infinity
Number.toexponential () format numbers with exponential notation
Number.tofixed () using fixed-point counting method to format digital
Number.tolocalestring () A string that converts a number to a cost format
Number.toprecision () format a valid bit of a number
Number.tostring () converts-a number to a string
Number.valueof () returns the original value
8.var str = new string ()//Declare a String object

Str.substr (start,length): Extracts and returns a substring in Str. However, it does not modify the Str,start representation of the start position of the extraction, length represents the lengths, omitting length, then the extraction to the end.

Str.substring (From,to): Returns a substring of string strings, consisting of characters from between to, including characters located from, excluding characters located to. If the from>to, is automatically replaced after interception.

Str.tolowercase (): Converting strings to lowercase

Str.touppercase (): Converting strings to uppercase

Str.split (): Follow the specified symbol for string segmentation

Str.slice (): Same as substring () but flexible, allow negative values, similar to Array.slice ()

Str.concat (): String link, with Array.concat think, but with + number more convenient

Str.indexof (): Retrieves the character, returns the position where the character first appears

9.var date=new Date ()//Create a Dates Object

Some of the main methods are:

Date.get/setday ()//return/Set one day of the week (0~6),

Date.get/setfullyear ()//return/Set the year in system time

Date.get/setmonth ()//Returns/sets the Month field in the system time (0~11)

Date.get/setdate ()//return/Set one day of one months

Date.get/sethours ()//return/Set the hour field in the system time

Date.get/setminutes ()//Returns/sets the Minutes field in the system time

Date.get/setseconds ()//return/Set the seconds field in the system time

Date.get/settime ()//Returns/sets//Returns/sets the minute field in the system time

10.var arr=new Array ()///Create an Array object

Main properties: Arr.length//Returns the length of the array

Main methods:

POPs ()//deletes and returns the last element of the array, returning the value to the deleted element

Push ()///Add elements to the end of the array to return the length of the array

Shift ()///move the first element to the array, returning the value to the deleted element

Unshift ()///Insert an element at the head of the array to return the length of the array

Slice ()//returns part of the array, the argument can be negative, returns the captured array

Reverse ()//reverse the order in the array, returning the inverted array

Sort ()//array element ordering, specifying method

Concat ()//array connection, returns the concatenated array, does not change the original array

Join ()///To concatenate an array element to a specified character and return as a string

Splice ()//inserts, deletes, or replaces elements of an array.

ToString ()//converting an array to a string

11.Math is a native object

Math.Abs ()//return absolute value

Math.ceil ()///Up rounding

Math.floor ()//Country rounding

Math.Round ()//rounding

Math.randow ()//returns a random number

Math.max ()//returns a larger value

Math.min ()//returns a smaller value

Math.PI ()//constant PI

Math.pow () The Y-power of the//x

MATH.SQRT ()//Compute squared

12. Other

isNaN ()//To determine whether a numeric value, not a value returns True

parseint ()//cast to integer type

Parsefloat ()//cast to floating-point values

Alert ()//Warning

Confirm ()//Message Confirmation box

Prompt ()//Hint message box

document.write ()//writes content to an HTML document, overwriting the entire HTML document if the document content is written with that method after it has been loaded

document.getElementById ()//Get object by ID name

Document.getelementstagname ()//Gets the object by tag name, returns an array object

Document.getelementsclassname ()//Gets the object by class name and returns an array object

The above mentioned is the entire content of this article, I hope you can enjoy.

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.