JavaScript Primer Basics Want to learn JS friends can refer to the basic knowledge

Source: Internet
Author: User
Stringobject.charat (Index) method: Returns the character at the specified index position.
Both the Stringobject.slice (Start,[end]) and stringobject.substring (Start,[end]) methods accept two parameters, which are the starting and ending positions of the substrings, and return the string between the two. The string that does not include the ending position. If you do not specify a second argument, the default is the length of the string, from the start position to the end of the string.
The difference between the two methods is mainly the difference between the handling of negative numbers. Negative arguments are counted forward from the end of the string for slice (), while substring () ignores negative numbers directly as 0来 processing, and 0 as the starting position and a positive number as the terminating bit. For example: substring (2,-3) is equivalent to substring (0,2)
Stringobject.substr (Start,[length]) method: Returns a string that takes length from the start of subscript start.
Stringobject.indexof (Searchstr,[fromindex]) method: Returns a string SEARCHSTR the index number that appears in the Stringobject string for the first time from the Fromindex. Returns 1 if STR is not included in the Stringobject. (Search backwards)
Stringobject.lastindexof (Searchstr,[fromindex]) Method: Returns the string searchstr from the Fromindex (starting at the end) to search the index number that appears in the Stringobject string for the first time. Returns 1 if STR is not included in the Stringobject. (Search from the back)
The parseint (String,[radix]) function parses a string and returns an integer. Radix indicates that you need to convert to a few (optional) numbers, and the default is decimal.
The parsefloat (string) function parses a string and returns a floating-point number.
The declaration of an array in javascript:
New Array ();
New Array (size);
New Array (Element0, Element0, ..., ELEMENTN);
[Element0, Element0, ..., ELEMENTN];
The Arrayobject.join ([separator]) method returns a string. The string is generated by converting each element of the arrayobject to a string and then connecting the strings to insert the separator string between the two elements.
The Stringobject.split (Separator,[howmany] method returns an array that is created by dividing the string stringobject into substrings at the boundary specified by separator. Howmany represents the maximum length (optional) of the returned array. Stringobject.split ("") can split the string stringobject into letters.
The Arrayobject.reverse () method reverses the order of elements in an array. no return value.
The Arrayobject.sort () method is used to sort the elements of an array. no return value.
JavaScript definition function
function functionname ([arg0,arg1,..., argn])
{
Statements
[Return[expression]]
}
Use the arguments object to access the parameters of the function. For example, Arguments[0] can access the value of the first parameter.
The Math.random () method can return a random number between 0 ~ 1.
BOM (Brower object model) browser objects
Includes: window,document,location,navigator and screen
The properties and methods commonly used by Window objects are:
Window.moveby (dx,dy): The browser window corresponds to the current position level to the right to move DX pixel, vertical downward move dy pixel;
Window.moveto (x,y): Move the browser window to the user screen (x,y);
Window.resizeby (DW,DH): relative to the current size of the browser window, increase the width of dw pixels, height increase dy pixel;
Window.resizeto (w,h): Adjust the width of the browser window to W pixel, height to H pixel;
window.open ([Newwindowurl],[newwindowname],[feature1,feature2 ...]) : Opens a new window. The newwindowname corresponds to the target attribute of the <a> tag.
Windowobject.opener: Access to open the original window windowobject;
Window.close (): Closes the current window;
Window.status= "...": Set the status bar text;
Window.alert ("..."): pop-up prompt information;
Window.confirm ("..."): Pop-up confirmation box;
Window.prompt ([Text],[defaulttext]): Pop-up input Prompt box, DefaultText is the default text (optional);
Window.history.go ( -1)/window.history.back (): one page back;
Window.history.go (1)/window.history.forward (): Forward one page.
The Document object is a property of a Window object that can be accessed by the Window.document property.
Common method: document.write ("...")
The Location object is a property of the Window object that can be accessed through the Window.location property.
Common Properties: Location.href=url
Navigator Objects
Common properties: navigator.useragent (usually the browser's judgment is done through this property). )
The screen object is also a property of the Window object.
Common Properties:
Screen.availheight: The screen height that the window can use;
Screen.availwidth: The screen width that the window can use;
Screen.colordepth: The number of digits that the user represents the color;
Screen.height: screen height;
Screen.width: Screen width.
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.