JavaScript Common Syntax (1-50)

Source: Internet
Author: User
Tags square root what array

1.The Document object is part of the Window object and can be accessed through the Window.document Property.

2.The Document.cookie property can set or query all cookies related to the current Document. This property is a readable, writable string that can be used to read, create, modify, and delete cookies for the current Document.

3.The Document.domain property returns the server domain name on which the current document is Downloaded. This property is a read-only string that contains the host name of the Web server that is loaded into the current Document.

4.The Document.referrer property returns the URL of the document loaded into the current Document. Null if the current document is not accessed through a hyperlink. This property allows client JavaScript to access the HTTP reference header.

5.The Document.title property returns the title of the current document (the text in the HTML title element).

6.Document. The URL property returns the URL to the current Document. In general, the value of this property is the same as the Location.href property of the Window that contains the Document. however, when URL redirection occurs, This URL property holds the actual URL of the document, and Location.href saves the requested Url.

7.The Document.close () method closes an output stream opened by the Document.open method and displays the selected Data.

var newdoc=document.open ("text/html", "replace");

var txt= "

Newdoc.write (txt);

Newdoc.close ();

8. document.getElementById (id), document.getelementsbyname (name), document.getelementsbytagname (tagname) , Document.open (mimetype,replace), document.write (exp1,exp2,exp3,....)

9.The prompt (text,defaulttext) method is used to display a dialog box that prompts the user for Input.

arguments The object represents the function being executed and the parameters of the function that called it, callee Returns the function object being executed, which is the body of the specified function object,Caller returns a reference to a function that invokes the current function, which is a member of the arguments object that represents a reference to the function object itself, which facilitates recursion of the anonymous function or guarantees the encapsulation of the function, such as the sum of the natural numbers of 1 to N for the callee of the example below. This property is available only if the related function is Executing. It is also important to note that callee has the length property, which is sometimes used for validation or better. Arguments.length is the length of the argument, and the arguments.callee.length is the length of the formal parameter, thus determining whether the parameter length is consistent with the argument Length.

Console.log (), which can be used to replace alert () or document.write (), which are general information Console.info (), Error-console.debug (), Warning Prompt console.warn (), error console.error (), console.group (), console.groupend (),console.dir (), Console.dirxml () is used to display the Html/xml code contained in a node of a web Page. var table = document.getElementById ("table1"); console.dirxml (table); Console.assert () is used to determine whether an expression or variable is True. If the result is no, a corresponding message is output in the console and an exception is Thrown.

The Apply method can hijack another Object's method, inheriting another object's property, obj: This object will replace the function class in the This object, args: this is an array, it will be passed as a parameter to function (args--> Arguments)//person.apply (this,arguments);

Call calls one method of an object, replacing the current object with another Object. Obj1.method1.call (obj2,argument1,argument2) as above, the role of call is to put Obj1 method on the obj2 to use, behind the argument1. These are passed as Arguments.

the . onclick event occurs when an object is Clicked. Please note that the onclick is different from onmousedown. Click event occurs when a Mouse-down event occurs after a Mouse-down event occurs on the same element.

the . string object is used to process text (strings). When string () and operator new are used as constructors, it returns a newly created string object that holds the string representation of the string s or s . When a string () is not called with the new operator, it only converts s to the original string and returns the converted Value.

The Split () method is used to split a string into an array of strings. If an empty string ("") is used as separator, then each character in the Stringobject is Split. The action performed by String.Split () is the opposite of what Array.join does.

The Splice () method is used to insert, delete, or replace elements of an array. Note that the splice () method works differently than the slice () method, and the splice () method modifies the array directly.

arr.splice(2,0,"William")

George,john,thomas,james,adrew,martin

George,john,william,thomas,james,adrew,martin

arr.splice(2,1,"William")

George,john,thomas,james,adrew,martin
George,john,william,james,adrew,martin

arr.splice(2,3,"William")

George,john,thomas,james,adrew,martin
George,john,william,martin

The Slice () method returns the selected element from an existing array. Note that the method does not modify the array, but instead returns a subarray. If you want to delete an element from an array, you should use method Array.splice ().

arr.slice(1),John,thomas
var arr = new Array (6) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas"
arr.slice(2,4)Thomas,james
19.onfocus="setStyle(this.id)"
20.The Confirm () method is used to display a dialog box with the specified message and OK and cancel Buttons. If the user clicks the OK button, confirm () returns True. If you click the Cancel button, confirm () returns FALSE.
the . parseint () function resolves a string and returns an Integer.
parseint ("10"); Returns 10
parseint ("19", 10); Returns 19 (10+9)
parseint ("11", 2); Returns 3 (10+9)
parseint ("17", 8); Returns 15 (8+7)
parseint ("1f", 16); Returns 31 (16+15)
parseint ("010"); Undecided: returns 10 or 8
the . Date () method returns the date and time of the current day. document.write (Date ()), Sat Jan 07 22:34:55 2017
newA Date () Date object automatically uses the current date and time as its initial Value.
The Date.getfullyear () method returns a 4-digit number that represents the Year.
The Date.getmonth () method returns a number that represents the month, using local Time. The return value is an integer between 0 (January) and 11 (December).
Date.getdate () Returns the day of the month and the return value is an integer between 1 and 31
The Date.gethours () method returns the hour field for the time, and the return value is an integer between 0 (midnight) and 23 (11 o'clock in the evening).
The Date.getminutes () method returns the minute field of Time. The return value is an integer between 0 and 59.
The Date.getseconds () method returns the seconds of the Time. The return value is an integer between 0 and 59.
The Date.getmilliseconds () method returns the milliseconds of the Time. The return value is an integer between 0 and 999
The Date.gettime () method can return the number of milliseconds from January 1, 1970.
. document.getElementById(‘myAnchor‘).innerHTML="W3School" ;
document.getElementById("td1").innerHTML
24.The SetInterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds). The SetInterval () method keeps calling functions until Clearinterval () is called or the window is Closed. The ID value returned by SetInterval () can be used as a parameter to the Clearinterval () method. int=  self.setInterval("clock()",1000), int=window.clearInterval(int)
   .   document.createelement () is to create an object in the object, To be used in conjunction with the AppendChild () or InsertBefore () method. Where the AppendChild () method adds a new child node at the end of the Node's child nodes List. The InsertBefore () method inserts a new node at any point in the Node's child nodes List. 
  <script type= "text/javascript";  
            var board = document.getElementById ("board");
            var e =   document.createelement ("input");
             E.type = "button";
            e.value = "this is a small example of a test load";
            var object = Board. AppendChild (e);
        </script>
Load a button in the label board with the property value "this is a small example of a test load."
 New Array (), new Object (), new String (), new number ()
 The toString () method converts a logical value to a string and returns the Result. Returns the string "true" or "false" based on the original Boolean value or the value of the Booleanobject Object. If the object calling the method is not a Boolean, an exception TypeError is Thrown. This method is called automatically when a Boolean object is used in a string environment.

the . toFixed () method rounds numbers to a number that specifies the number of decimal digits.

The Anchor object represents an HTML Hyperlink.
 The CharAt () method returns the character at the specified Position. Note that JavaScript does not have a character data type that differs from the string type, so the returned character is a string of length 1. The subscript for the first character in a string is 0. If the parameter index is not between 0 and string.length, the method returns an empty String.
 The charCodeAt () method returns the Unicode encoding of the character at the specified Position. This return value is an integer between 0-65535. Method charCodeAt () is similar to the operation performed by the CharAt () method, except that the former returns the encoding of the character at the specified position, and the latter returns a character string. The subscript for the first character in a string is 0. If index is a negative number, or is greater than or equal to the length of the string, charcodeat () returns NaN.
 The IndexOf () method returns the position of the first occurrence of a specified string value in a string. The IndexOf () method is case-sensitive! If the string value that you want to retrieve does not appear, the method returns-1.
The LastIndexOf () method returns the last occurrence of a specified string value, which is searched from behind in a string at the specified Position. The LastIndexOf () method is case-sensitive! If the string value that you want to retrieve does not appear, the method returns-1.

The Match () method retrieves the specified value within a string, or finds a match for one or more regular expressions. The method is similar to IndexOf () and lastIndexOf (), but it returns the specified value instead of the position of the String.

If RegExp does not have a flag g, then the match () method can only perform a match in Stringobject. If no matching text is found, match () returns Null. otherwise, it returns an array that holds information about the matching text it finds. The No. 0 element of the array holds the matching text, while the rest of the elements hold the text that matches the subexpression of the regular Expression. In addition to these regular array elements, the returned array contains two object Properties. The Index property declares the position of the starting character of the matching text in stringobject, and the input property declares a reference to Stringobject.

If RegExp has the flag g, the match () method performs a global retrieval and finds all matching substrings in the Stringobject. If no matching substring is found, null is Returned. If one or more matching substrings are found, an array is Returned. however, the contents of the array returned by the global match are very different from the former, and its array elements hold all the matching substrings in the stringobject, and there is no index attribute or input Property.

The Replace () method can replace the current document with a new ONE. The Replace () method does not generate a new record in the history object. When you use this method, the new URL overwrites the current record in the history object.window.location.replace("http://www.w3school.com.cn")

35.The Search property sets or returns the portion of a query string that is Link-url in a range. Areaobject.search=querystring

The toUpperCase () method is used to convert a string to Uppercase. Stringobject.touppercase ()

The toLocaleLowerCase () method is used to convert a string to Lowercase. Stringobject.tolocalelowercase ()

The Pns. substring () method is used to extract the character of a string intermediary between two specified subscripts. Stringobject.substring (start,stop), Unlike the slice () and substr () methods, substring () does not accept negative arguments.

var str= "Hello world!", document.write ( str.substring(3) ), Lo world!
var str= "Hello world!", document.write ( str.substring(3,7) ), Lo W
The substr () method extracts a specified number of characters from the start subscript in a string. Stringobject.substr (start,length), substr () parameter specifies the starting position and length of the substring, so it can be used instead of substring () and slice (). ECMAscript did not standardize the method and therefore objected to its use.
Math.Abs returns the absolute value of a number
The Math.sqrt method returns the square root of a number.
The Measure. sort () method is used to sort the elements of an array. Arrayobject.sort (sortby)

The join () method is used to put all the elements in an array into a string. Arrayobject.join (separator), returns a string. The string is generated by converting each element of Arrayobject to a string and then connecting the strings to insert a separator string between the two Elements.

The pop () method is used to delete and return the last element of the Array. The pop () method removes the last element of the arrayobject, reducing the length of the array by 1, and returning the value of the element it Deletes. If the array is already empty, pop () does not change the array and returns the undefined Value.

The. Push () method adds one or more elements to the end of the array and returns the new Length. The return value is the length of the array

The shift () method removes the first element from the array and returns the value of the first Element. The return value is the value of the original first element of the Array.

The Unshift () method adds one or more elements to the beginning of the array and returns the new Length. The return value is the new length of the Arrayobject.
The Concat () method is used to connect two or more arrays. Arrayobject.concat (arrayx,arrayx,......, Arrayx) returns a new array
The reverse () method reverses the order of the elements in the Array. The method changes the original array without creating a new array.
Window.screen.availHeight returns the height of the display screen (in addition to the Windows taskbar).
Window.screen.availWidth returns the width of the display screen (in addition to the Windows taskbar).
Window.screen.height returns the height of the display Screen.
Window.screen.width  Returns the width of the display Screen.
Window.innerheight your current browser content display window height
Window.innerwidth your current browser content display window width
Window.outerheight your current browser entire height
Window.outerwidth your current browser entire width
The SetTimeout () method is used to call a function or evaluate an expression after a specified number of MILLISECONDS.
SetTimeout (CODE,MILLISEC)
SetTimeout () executes code only ONCE. If you want to call more than once, use setinterval () or let code itself call SetTimeout () Again.
OnClick Click event
Window.onload after the page load is complete
onchange when elements change
Get Focus Event onfocus
Lost Focus Event Onblur
Mouse over Event onmouseover
Mouse Move Event onmouseout
The onsubmit event occurs when the confirmation button in the form is Clicked.
this.children;
The ParentNode property returns the parent node of the specified Node.
The parsefloat () function resolves a string and returns a floating-point number.
The ChildNodes property returns a collection of child nodes of the node to NodeList the Object.
The content from the starting position to the terminating position, but it removes the HTML tag.
The GetAttribute () method returns the property value of the specified property name to Attr the Object.
The NodeType property returns the type of the node
For text nodes, The NodeValue property contains Text.
The eval () function computes a string and executes the JavaScript code in it.

JavaScript Common Syntax (1-50)

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.