How to get started with JavaScript • Object Attribute method Large Sum _ Basics

Source: Internet
Author: User
Tags arrays current time eval function definition getdate natural logarithm square root time in milliseconds
Today is the final section of our JS Introductory series demo (which I planned for the time being), but please friends remember, the previous example you are very familiar with the words does not mean that we understand JS, and even we have to admit that we are just standing on the threshold, have not entered it, then you may want to ask, Why do you want to end it in a hurry? The answer is simple, our ultimate goal is ajax/atlas, in the future introductory tutorials we will also touch a lot of js things, and I this lazy person's cumbersome comments will not let you down, so more JS we continue to learn, the following we must put JS the most important things-"object" Methods and properties are familiar, because this is very important, and this post you can be collected, later use. Do not deny that we are geniuses, but more can not deny that we are not hard, even if the hard drive will have a bad way, who can guarantee that all remember to live?


Array: An ordered set of elements of a series;

Detailed demo please see: [JS Introductory series demo • array] http://www.cnblogs.com/thcjp/archive/2006/08/04/467761.html

Property:

Length: Used to get the number of array elements, the largest subscript plus 1

Method:

Sort (function): In the case of unspecified sorting numbers, sorted by the alphabetical order of the elements, if not a string type, and then converted to a string;

Reverse (): Reverses the order of elements in an array;

Concat (Array1,arrayn): Used to merge n arrays into a array1 array;

Join (String): Used to combine elements of an array into strings, string as delimiters, or, if omitted, to merge directly without separating;

Slice (start,stop): Used to return elements from start to stop in an array, and if the argument is negative, the countdown start or stop element;

ToString (): Returns all elements of an array to a string separated by commas;


--------------------------------------------------------------------------------

String: There's nothing to explain, detailed presentation see [JavaScript Getting Started JS core language-strings (string)] http://www.cnblogs.com/thcjp/archive/2006/08/11/474563.html
Property:

Length: Used to return string lengths, as in arrays;

Method:

Anchor (): This method creates a tag like anchor in HTML, format <a name= "" .....>, Access String.anchor (Chorname) by the following methods
For example document.write ("to the sky to wear. Net\ajax\atlas Blog to see more Tutorials" +mylink.link ("http://www.cnblogs.com/thcjp/"))

toUpperCase (): Converts a string to uppercase;

toLowerCase (): Converts a string to lowercase;

IndexOf (A,B): Looks up the position of character A in the string from the B character and returns, if B is omitted, the default from 0 position;

Chartat (i): Returns the first character of the string;

SUBSTRING (start,end): Returns all the characters from the Start-end in the string (but does not return the character of the end itself);

Sub (): Displays the specified string in subscript format;


--------------------------------------------------------------------------------

Date: Detailed demo see: JS Introduction • Dynamic clock, show complete some methods, New Year countdown http://www.cnblogs.com/thcjp/archive/2006/08/16/478313.html

To define a method:

A:var newdt=new Date ()--> creates a time object and assigns the value to the current time;
B:var newdt=new Date (milliseconds)--> creates a time object and sets the value of the object in milliseconds by the GTM delay time;
C:var newdt=new Date (string)--> uses a specific time string to assign a value to a newly created time object in a format that matches the parse method of the Date object;
D:var newdt=new date (year, month, day, hour, minute, second, millisecond)--> assigns values to objects in the order of year, month, day, hour, minute, second, millisecond;

Methods: Get time; set time; format conversion

A: Get Time

GetDate ()-----Get the current full time;
GetYear ()------Get the current year
Getmonths ()----Get the current month
Getday ()-------Get the current date day
GetHours ()-----Get the current hour
Getminutes ()---Get the current minute
Getseconds ()---Get the current second
GetTime ()------Get the current time, in seconds
gettimezoneoffset--get the current time zone offset information

B: Set time

In contrast to the above, the get is replaced with set, such as GetDate ()---> setdate ()

C: Conversion methods

Togtmstring ()------A string converted to a Greenwich mean time expression;
toLocaleString ()----A string converted to local time expression
ToString ()----------convert time to String
Parse---------------read the time from the string that represents the time
UTC-----------------return the gap from Greenwich Mean time to a specified time in milliseconds


--------------------------------------------------------------------------------
Math Math: Demo examples See Getting Started with JavaScript · JavaScript Math Object Demo http://www.cnblogs.com/thcjp/archive/2006/08/12/475100.html
Properties: Note that attributes in a mathematical object are read

E (=2.7182)------The bottom of the natural logarithm (specific meaning, I do not understand, alas, and mathematical close to the things I do not understand, depressed!) )
LN10 (=2.30259)---the natural logarithm of 10;
LN2 (=0.69315)-----The natural logarithm of 2;
Pi (=3.1415926)----PI
Square root of Sqrt1_2 (=0.7071)--1/2
SQRT2 (=1.4142)----square root of 2
LOG2E (=1.44269)---with 2 as the base, the logarithm of E
LOG10E (=0.43429)--logarithm of the base e of 10

Method: Actually use not much, depressed, all get out

Sin (a)----to find the sine of a
COS (a)------to find the cosine of a
Tan (a)------to find the tangent of a
ASIN (a)-----the inverse chord value of a
Atan (a)-----to find the inverse cosine value of a
EXP (a)------index of a
Log (a)------to find the natural logarithm of a
Pow (a,i)----to the I-side (the exponentiation) of a
Round (a)----rounding a
sqrt (a)-----find the square root of a
ABS (a)------to find the absolute value of a
Random ()----Take random numbers
Max (A,B)----take a larger number
Min (a,b)----take a smaller number

Note: The parameters of the function are floating-point types, and the trigonometric function is the radian value, not the degree


--------------------------------------------------------------------------------

JavaScript's built-in functions

Demo: [JavaScript Primer • Simple operation and data type conversion] Http://www.cnblogs.com/thcjp/archive/2006/08/03/467150.html

Escape () and unescape (): Encode and decode strings

Eval (String): Used to execute the operation or statement represented by a string
For example: Var a=0; var str1= "A+=a"; eval (str1);

parseint () and parsefloat (): Converts the value of a text box to an integer or floating-point number

Note: parseint () is not rounding the numbers, but cutting the tail

isNaN (): The complete E-text is (are not a number), as the name implies is to determine whether the string is a numeric, such as if (isNaN ("Sky-Piercing Series tutorial"))


--------------------------------------------------------------------------------

Custom objects: Two methods of objects with initialization objects and defining constructors

Detailed Demo: JavaScript Introductory series Demo • Function definition and simple parameter use, call function http://www.cnblogs.com/thcjp/archive/2006/08/04/467487.html
[JS Getting Started instance the definition and invocation of constructor \ Method \ prototype Object] Http://www.cnblogs.com/thcjp/archive/2006/08/02/466100.html

A: Initializing objects

For example: Object ={Property 1: Value 1; Property 2: Value 2; Attribute N: Value n}, note that each property \ value pair is separated by semicolons;

B: Define the object of the constructor

For example:
function functions Name (property 1, Property 2, ...). Attribute N) {

this. Property 1 = property value 1;
this. Property 2 = property value 2;
This. Property N= property value N;

This. Method Name 1 = function Name 1;
This. Method Name 2 = function Name 2;

}

Note: The method name and function name can have the same name, but before the method calls the function, the function must already be defined, or there will be an error.

Just as you create a new instance for a custom function, you use the newly statement.


--------------------------------------------------------------------------------

Browser objects
Window object: He belongs to the central class, at the highest level of all objects, plainly, without him, you all did not play;

Demo See: JS Introduction • Mobile form/pop-up prompts http://www.cnblogs.com/thcjp/archive/2006/08/03/466981.html
JavaScript Getting Started Series demo • Usage examples for three pop-up dialog boxes http://www.cnblogs.com/thcjp/archive/2006/08/04/468047.html

Properties: The main features are as follows

Closed----------used to determine whether the window is closed;
Opener The Open () method----------Store The window's parent window;
Defaultstatus the information displayed by default---status bar;
Status----------information currently displayed in the State bar;
Document,location,history---Very important, later in detail, if you don't want to wait, just look here

Method:

Alert (text)-------------pops up a message box
Confirm (text)-----------Confirmation information box, parameter is confirmation information
Prompt (Text,default)----Pop-up input dialog box, parameter is the hint information and the default value


--------------------------------------------------------------------------------

Document object: Includes various features of the current Web page, such as title \url\ background \ Language \ Modify time, etc.

Demo See: JavaScript Primer · Introduction to document objects (Access form, create new page, get page title) http://www.cnblogs.com/thcjp/archive/2006/08/08/470997.html
JS Getting Started • Open/close the specified URL window/Change the link time status bar text http://www.cnblogs.com/thcjp/archive/2006/08/04/468017.html

Property:

Title------------Document titles
LastModified-----File Last Modified
URL--------------The address of the page corresponding to the document
Cookie-----------used to create and get cookie information
bgcolor----------the background color of a document
Fgcolor----------Document foreground color
Location---------Save All page address information for the document
Alinkcolor-------Activate the color of the connection
LinkColor--------The color of the link
Vlinkcolor-------The colors of the links that have been browsed

Method:

Write (text)-----writes text or labels to a document without wrapping the line
Writeln (text)---Write text or labels to a document, wrapping at the last character
Open ()----------opens a new document such as Open ("Address", "Window name", "style")
Close ()---------closes the current document


--------------------------------------------------------------------------------

Location object: Contains all page address information for the current document

Property:

Protocol-----------Communication Protocol
The host name of the Web server on which the host---------------page resides
Port number for Port---------------server communication
Pathname-----------The path to the document on the server
Hash---------------anchor information for page jumps
Searce-------------page submitted to the server for search information
Hostname-----------Host name and port number, separated by colons in the middle
href---------------full URL address

Method:

Assign (URL)--------Navigate the page to another address
Reload-------------Refresh Page
Replace (URL)-------Replace the current page with a page with the specified URL


--------------------------------------------------------------------------------

History: This object includes previously accessed URL information

Attribute: Length, returns the number of URLs, mainly by Go (n), which loads a relative page by using the method

This article, I used a day more than summed up, I hope to reprint the word note name source it, I really write very hard!!

Turn from: Oh, my God. Net/vs2005/ajax Introduction
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.