Home  >  Article  >  Web Front-end  >  Summary of Javascript object attribute methods_javascript skills

Summary of Javascript object attribute methods_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:13:34998browse

数组(Array):系列元素的有序集合

属性:

length:用于获取数组元素的个数,既最大下标加 1

方法:

sort(function):在未指定排序号的情况下,按照元素的字母顺序排列,如果不是字符串类型则转换成字符串,在排序;

reverse():颠倒数组中元素的顺序;

concat(array1,arrayn):用于将N个数组合并到array1数组中;

join(string):用于将数组中元素合并为字符串,string为分隔符,如省略参数,则直接合并,不加分隔;

slice(start,stop):用于返回数组中start到stop中的元素,如果参数为负,则表示倒数start或stop个元素;

toString():将数组所有元素返回一个字符串,其间用逗号分隔;

字符串(string)

属性:

length:用于返回字符串的长度,用法与数组一样;

方法:

anchor():该方法创建如同HTML中的anchor一样的标记,格式 ,通过下列方法访问 string.anchor(chorName)

toUpperCase():将字符串转换成大写;

toLowerCase():将字符串转换成小写;

indexOf(a,b):从第 b 个字符查找字符 a 在字符串中出现的位置并返回,如果 b 省略,则默认从 0 位置查找;

chartAt(i):返回字符串中第 i 个字符;

substring(start,end):返回字符串中从 start - end 之间的全部字符(但是不返回end本身那个字符哦);

sub():将指定的字符串用下标格式显示;
 

日期(Date):详细演示见

定义方法:

a: var newdt=new Date() -->创建时间对象并赋值为当前时间;
b: var newdt=new Date(milliseconds) --> 创建时间对象,且以GTM的延迟时间来设置对象的值,单位为毫秒;
c:var newdt=new Date(string) -->使用特定的时间字符串为新创建的时间对象赋值,其格式与Date对象的parse方法匹配;
d: var newdt=new Date(年,月,日,小时,分,秒,毫秒) -->按照年,月,日,小时,分,秒,毫秒 的顺序为对象赋值;

方法:获取时间;设置时间;格式转换

A:获取时间

getDate() -----获取当前完整时间;
getYear()------获取当前的年
getMonths()----获取当前的月份
getDay()-------获取当前的日期 天
getHours()-----获取当前的小时
getMinutes()---获取当前的分钟
getSeconds()---获取当前的秒
getTime()------获取当前的时间,单位 秒
getTimeZoneOffset--获取当前的时区偏移信息

b:设置时间

对照上面的获取,把get换成 set 即可,例如 getDate() ---> setDate()

c:转换方法

toGTMString() ------转换成格林威治标准时间表达式的字符串;
toLocaleString()----转换成当地时间表达的字符串
toString()----------把时间转换成字符串
parse---------------从表示时间的字符串中读出时间
UTC-----------------返回从格林威治标准时间到指定时间的差距,单位为 毫秒


Math 数学:

属性:注意,数学对象中的属性是指读的

E (=2.7182) ------自然对数的底(具体意思,我不明白,唉,和数学密切的东西我都不明白,郁闷!)
LN10(=2.30259) ---10的自然对数;
LN2(=0.69315)-----2的自然对数;
PI(=3.1415926)----圆周率
SQRT1_2(=0.7071)--1/2的平方根
SQRT2(=1.4142)----2的平方根
LOG2E(=1.44269)---以2为底,E的对数
LOG10E(=0.43429)--以10为底E的对数

方法: 其实用得上的不多,郁闷,全部弄出来吧

sin(a) ---- 求a的正弦值
cos(a)------求a的余弦值
tan(a)------求a的正切值
asin(a)-----求a的反正弦值
atan(a)-----求a的反余弦值
exp(a)------求a的指数
log(a)------求a的自然对数
Pow(a,i)----求a的i次方(乘方)
round(a)----对a进行四舍五入运算
sqrt(a)-----求a的平方根
abs(a)------求a的绝对值
random()----取随机数
max(a,b)----取较大的数
min(a,b)----取较小的数

注意:函数的参数均是浮点类型,三角函数的参数为弧度值,而不是度
 

JavaScript的内置函数

escape() 与 unescape() :对字符串进行 编码与解码

eval(字符串):用于执行字符串所代表的运算或语句
        例如:var a=0; var str1="a+=a"; eval(str1);

parseInt() 和 parseFloat():将文本框的值转换成整数 或 浮点数

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

isNaN(): The complete E text is (is not a number). As the name suggests, it is to determine whether the string is a number, such as if(isNaN("天blastpiercing series tutorial"))

Custom objects: There are two methods: initializing objects and objects defining constructors

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 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 valuen;

this.methodname1=functionname1;
this.methodname2=functionname2;
}

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: He belongs to the central level, the highest level of all objects. To put it bluntly, without him, you would have nothing to play;

Properties:

closed----------used to determine whether the window is closed;
er----------stores the parent window of the window opened by the () method;
defaultstatus- --The information displayed by default in the status bar;
status----------The information currently displayed in the status bar;
Document, Location, History---very important, will be discussed in detail later, if Don’t want to wait, just look here

Method:

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


document object: includes each of the current web page Features, such as title URL background language modification time, etc.

Properties:

title------------Document title
lastModified-----File last modified time
URL--------------Document The corresponding page address
Cookie-----------used to create and obtain Cookie information
bgColor----------the background color of the document
fgColor-- --------The foreground color of the document
location---------Save all page address information of the document
alinkcolor-------The color of the activated link
linkcolor--------The color of the link
vlinkcolor------The color of the viewed link

Method:

write(text)---Write text or labels to the document without line breaks
writeln(text)---Write text or labels to the document with line breaks at the last character
( )----------Open a new document such as ("Address", "Window Name", "Style")
close()---------Close the current document

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

Properties:

protocol-----------Communication protocol
host---------------The host name of the WEB server where the page is located
port--- ------------Port number for server communication
pathname----------The path of the document on the server
hash-------- -------Anchor tag information for page jump
searce-------------Search information submitted by the page to the server
hostname------- ----Host name and port number, separated by colon
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 information about previously visited URLs

Attribute: length, returns the number of URLs

The main method is go(n), through which the relative page is loaded