天天看點

JavaScript的内置對象和函數

javascript 内置對象:1.Date 2.Math 3.Number 4.Boolean 5.String 6.Array 7.RegExp

8.Function

屬性:

arguments    An array corresponding to the arguments passed to a function.

arity      Indicates the number of arguments expected by the function.

caller      Specifies which function called the current function.

prototype    Allows the addition of properties to a Function object.

方法:

toString     Returns a string representing the specified object.

9.Object

屬性:

constructor Specifies the function that creates an object's prototype.

prototype    Allows the addition of properties to all objects.

方法:

eval       Evaluates a string of JavaScript code in the context of the specified object.

toString     Returns a string representing the specified object.

unwatch     Removes a watchpoint from a 屬性源 the object.

valueOf     Returns the primitive value of the specified object.

watch      Adds a watchpoint to a 屬性源 the object.

10.全局

屬性:

Infinity     指定一個正負無窮大的數值

NaN       指定一個 “非數字” 值

undefined    指定一個未被指派的變量

11.事件

屬性:

a.視窗事件,隻在body和frameset元素中才有效

onload      頁面或圖檔加載完成時

onunload     使用者離開頁面時

b.表單元素事件,在表單元素中才有效

onchange     框内容改變時

onsubmit     點選送出按鈕時

onreset     重新點選滑鼠按鍵時

onselect     文本被選擇時

onblur      元素失去焦點時

onfocus     當元素擷取焦點時

c.鍵盤事件,在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title元素裡都無效

onkeydown    按下鍵盤按鍵時

onkeypress    按下或按住鍵盤按鍵時

onkeyup     放開鍵盤按鍵時

d.在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title元素裡都無效

onclick     滑鼠點選一個對象時

ondblclick    滑鼠輕按兩下一個對象時

onmousedown 滑鼠被按下時

onmousemove 滑鼠被移動時

onmouseout    滑鼠離開元素時

onmouseover 滑鼠經過元素時

onmouseup    釋放滑鼠按鍵時

e.其他

onresize     當視窗或架構被重新定義尺寸時

onabort     圖檔下載下傳被打斷時

onerror     當加載文檔或圖檔時發生錯誤時

自定義對象:有初始化對象和定義構造函數的對象兩種方法

a:初始化對象

例如: 對象={屬性1:值1;屬性2:值2;......屬性n:值n} 注意:每個屬性/值對之間用分号隔開;

b: 定義構造函數的對象

例如:

function 函數名(屬性1, 屬性2,......屬性N){

this.屬性1=屬性值1;

this.屬性2=屬性值2;

this.屬性n=屬性值n;

this.方法名1=函數名1;

this.方法名2=函數名2;

}

注意:方法名和函數名可以同名,但是在方法調用函數前,函數必須已經定義好,否則會出錯

為自定義的函數建立新的執行個體一樣是使用 new 語句。

繼續閱讀