Home > Web Front-end > JS Tutorial > body text

Introduction to JavaScript·Summary of object attribute methods_Basic knowledge

WBOY
Release: 2016-05-16 19:08:35
Original
848 people have browsed it

Today is the last section of our js introductory series of demonstrations (this is my plan for the time being), but please remember, friends, if you are familiar with the previous examples, it does not mean that we understand JS, or even get started with us. We all have to admit that we are just standing on the threshold and have not entered yet. Then you may ask, why should we end it in a hurry? The answer is simple. Our ultimate goal is AJAX/Atlas. In the future introductory tutorials, we will also be exposed to a lot of JS stuff, and I, a lazy person, will definitely not disappoint you with my complicated comments, so we will introduce more JS We will continue to study in the future. Next, we must be familiar with the most important thing in JS - the methods and properties of "Object", because this is very important, and you can save this Post and use it later.We do not deny that we are all geniuses, but we cannot deny that we are not hard drives. Even if we are, the hard drives will still have bad sectors. Who can guarantee that we will remember them all?


Array: an ordered collection of series elements;

Please see the detailed demonstration: [js entry series demonstration·array] http://www.cnblogs.com/ thcjp/archive/2006/08/04/467761.html

Attributes:

length: used to get the number of array elements, that is, the maximum subscript plus 1

Method:

sort(function): When the sort number is not specified, the elements are arranged in alphabetical order. If it is not a string type, it is converted to a string and then sorted;

reverse (): Reverse the order of elements in the array;

concat(array1,arrayn): Used to merge N arrays into the array1 array;

join(string): Used to combine arrays The elements in are merged into strings, and string is the separator. If the parameter is omitted, it will be merged directly without separation;

slice(start,stop): used to return the elements from start to stop in the array, if If the parameter is negative, it means the countdown start or stop elements;

toString(): Returns all elements of the array into a string, separated by commas;


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

String (string): There is nothing to explain. For a detailed demonstration, please refer to [Javascript Introduction] ·js core language - string (string)] http://www.cnblogs.com/thcjp/archive/2006/08/11/474563.html
Attribute:

length: used Returns the length of the string, the usage is the same as the array;

method:

anchor(): This method creates a tag like anchor in HTML, format , accessed through the following methods string.anchor(chorName)
For example document.write("Go to Tianbangchuan.netajaxatlas blog for more tutorials" myLink.link("http://www.cnblogs.com/thcjp/"))

toUpperCase(): Convert the string to uppercase;

toLowerCase(): Convert the string to lowercase;

indexOf(a,b): Search from the bth character The position where character a appears in the string is returned. If b is omitted, it will be searched from position 0 by default;

chartAt(i): Returns the i-th character in the string;

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

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


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

Date : For detailed demonstration, please see: Getting Started with js·Dynamic Clock, Some Complete Methods of Display, New Year Countdown http://www.cnblogs.com/thcjp/archive/2006/08/16/478313.html

Definition Method:

a: var newdt=new Date() --> Create a time object and assign it to the current time;
b: var newdt=new Date(milliseconds) --> Create a time object, and Set the value of the object based on the GTM delay time, in milliseconds;
c: var newdt=new Date(string) --> Use a specific time string to assign a value to the newly created time object, and its format is the same as the Date object The parse method matches;
d: var newdt=new Date (year, month, day, hour, minute, second, millisecond) --> In the order of year, month, day, hour, minute, second, millisecond, it is Object assignment;

Methods: Get time; set time; format conversion

A: Get time

getDate() ----- Get the current complete time;
getYear()------Get the current year
getMonths()----Get the current month
getDay()-------Get the current date days
getHours()-----Get the current hours
getMinutes()---Get the current minutes
getSeconds()---Get the current seconds
getTime()------ Get the current time in seconds
getTimeZoneOffset--get the current time zone offset information

b: Set the time

Contact the above acquisition, just replace get with set, for example getDate() ---> setDate()

c: Conversion method

toGTMString() ------Convert to a string of Greenwich Mean Time expression;
toLocaleString()----Convert to a string expressing local time
toString()----------Convert time into a string
parse-------- -------Read the time from a string representing time
UTC-----------------Returns the difference from Greenwich Mean Time to the specified time , the unit is milliseconds


---------------------------------------- ---------------------------------------------
Math: Demonstration For examples, see Getting Started with JavaScript · JavaScript Math Object Demonstration http://www.cnblogs.com/thcjp/archive/2006/08/12/475100.html
Attributes: Note that the attributes in math objects are read

E (=2.7182) ------The base of natural logarithms (I don’t understand the specific meaning. Alas, I don’t understand anything closely related to mathematics. It’s frustrating!)
LN10(=2.30259) ---the natural logarithm of 10;
LN2(=0.69315)-----the natural logarithm of 2;
PI(=3.1415926)----pi
SQRT1_2(=0.7071)--The square root of 1/2
SQRT2(=1.4142)----The square root of 2
LOG2E(=1.44269)---With base 2, the logarithm of E
LOG10E (=0.43429)--The logarithm of E based on base 10

Method: Actually it’s not very useful, I’m depressed, just get them all

sin(a) ----Find the sine value of a
cos(a)------Find the cosine value of a
tan(a)------Find the tangent value of a
asin( a)-----Find the inverse sine of a
atan(a)-----Find the inverse cosine of a
exp(a)------Find the exponent of a
log(a)------Find the natural logarithm of a
Pow(a,i)----Find the i-th power (power) of a
round(a)--- -Perform rounding operation on a
sqrt(a)-----Find the square root of a
abs(a)------Find the absolute value of a
random()---- Take the random number
max(a,b)----take the larger number
min(a,b)----take the smaller number

Note: Parameters of the function They are all floating point types, and the parameters of trigonometric functions are radian values, not degrees


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

JavaScript's built-in functions

For a demonstration, see: [Introduction to javascript·Simple operations 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 string represented by Operation or statement
For example: var a=0; var str1="a =a"; eval(str1);

parseInt() and parseFloat(): Convert the value of the text box into an integer or Floating point number

Note: parseInt() does not round the number, but trims the tail

isNaN(): The complete E text is (is not a number), as the name implies, it is a judgment character Whether the string is a number, for example if(isNaN("天blastpiercing series tutorial"))


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

Custom object: There are two methods of initializing the object and defining the constructor function

For detailed demonstration, please see: JavaScript entry series demonstration·function definition and simplicity Parameter usage, calling functions http://www.cnblogs.com/thcjp/archive/2006/08/04/467487.html
[Definition of constructor method and calling prototype object of js entry example] http:// www.cnblogs.com/thcjp/archive/2006/08/02/466100.html

a: Initialization object

For example: object = {attribute 1: value 1; attribute 2: value 2;...Attribute n: value n}, note that each attribute value pair is separated by a semicolon;

b: Object defining the constructor

For example :
function function name (attribute 1, attribute 2,. . . Attribute N){

this.Attribute1=attribute value 1;
this.Attribute2=attribute value 2;
this.Attributen=attribute 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 have been defined, otherwise an error will occur

To create a new instance of a custom function, use the new statement.


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

Browser Object
Window object: It belongs to the central level and is at the highest level of all objects. To put it bluntly, without it, you would have nothing to play;

For a demonstration, see: js entry·mobile form/pop-up prompt http: //www.cnblogs.com/thcjp/archive/2006/08/03/466981.html
Javascript entry series demonstration·Usage examples of three pop-up dialog boxes http://www.cnblogs.com/thcjp/archive /2006/08/04/468047.html

Attributes: The main ones are as follows

closed----------used to determine whether the window is closed;
opener ----------Stores the parent window of the window opened by the open() method;
defaultstatus---the information displayed by default in the status bar;
status----------status The information currently displayed in the column;
Document, Location, History---very important, I will explain it in detail later, if you don’t want to wait, just look here

Method:

alert(text) -------------A prompt message box pops up
confirm(text)----------Confirm message box, the parameter is confirmation message
prompt(text) ,default)----pops up the input dialog box, the parameters are prompt information and default value


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

Document object: including various features of the current web page, such as title URL background language modification time, etc.

For a demonstration, see: Getting Started with JavaScript·Document Object Introduction (Access the form, create a new page, get the page title) http://www.cnblogs.com/thcjp/archive/2006/08/08/470997.html
JS Getting Started·Open/Close the window/change of the specified URL The text in the status bar when linking http://www.cnblogs.com/thcjp/archive/2006/08/04/468017.html

Attribute:

title------ ------Document title
lastModified-----File last modified time
URL--------------The page address corresponding to the document
Cookie-- ---------Used to create and obtain Cookie information
bgColor----------The background color of the document
fgColor----------The document Foreground color
location---------save all page address information of the document
alinkcolor-------activate the color of the connection
linkcolor--------link The color of
vlinkcolor-------The color of the browsed link

Method:

write(text)-----Write text or tags to the document , no line break
writeln(text)---Write text or tags to the document, wrap the line at the last character
open()----------Open a new document For example, open( "Address", "Window name", "Style")
close()---------Close the current document


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

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

Attribute:

protocol-----------Communication protocol
host---------------The host name of the WEB server where the page is located
port----- ----------Port number for server communication
pathname----------Document path on the server
hash---------- -----The anchor tag information for page jump
searce-------------The search information that the page submits to the server
hostname--------- --The name and port number of the host, separated by colons
href---------------Complete URL address

Method:

assign(URL)--------Navigate the page to another address
reload-------------Refresh the page
replace(URL)--- ----Use the page with the specified URL to replace the current page


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

History: This object includes previously visited URL information

Attribute: length, returns the number of URLs, the main method is go(n), through which the relative page is loaded

It took me more than a day to summarize this article. I hope that if you want to reprint it, please indicate the source. I really worked hard to write it!!

Reprinted from:
day Getting Started with .net/vs2005/ajax

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template