1. 程式人生 > >javaScript內建函式大全

javaScript內建函式大全

1.Date:日期函式
屬性(1):
constructor 所修立物件的函式參考
prototype 能夠為物件加進的屬性和方法
辦法(43):
getDay() 返回一週中的第幾天(0-6)
getYear() 返回年份.2000年以前為2位,2000(包括)以後為4位
getFullYear() 返回完全的4位年份數
getMonth() 返回月份數(0-11)
getDate() 返回日(1-31)
getHours() 返回小時數(0-23)
getMinutes() 返回分鐘(0-59)
getSeconds() 返回秒數(0-59)
getMilliseconds() 返回毫秒(0-999)
getUTCDay() 依據國際時間來得到如今是禮拜幾(0-6)
getUTCFullYear() 根據邦際時間來失掉完全的年份
getUTCMonth() 依據國際時間來得到月份(0-11)
getUTCDate() 依據國際時間來失掉日(1-31)
getUTCHours() 依據國際時間來失掉小時(0-23)
getUTCMinutes() 根據邦際光陰來往歸分鐘(0-59)
getUTCSeconds() 依據國際時間來返回秒(0-59)
getUTCMilliseconds()依據國際時間來返回毫秒(0-999)
getTime() 前往自1970年1月1號0:0:0到如今一同花來的毫秒數
getTimezoneoffset() 往歸時區偏偏差值,便格林威亂均勻時光(GMT)取運轉足原的盤算機所處時區設定之間相差的分鐘數)
parse(dateString) 返回正在Date字串中自從1970年1月1日00:00:00以來的毫秒數
setYear(yearInt) 設定年份.2位數或4位數
setFullYear(yearInt)設定年份.4位數
setMonth(monthInt) 設放月份(0-11)
setDate(dateInt) 設定日(1-31)
setHours(hourInt) 設定小時數(0-23)
setMinutes(minInt) 設定分鐘數(0-59)
setSeconds(secInt) 設放秒數(0-59)
setMilliseconds(milliInt) 設放毫秒(0-999)
setUTCFullYear(yearInt) 依據國際時間來設定年份
setUTCMonth(monthInt) 依據國際時間來設定月(0-11)
setUTCDate(dateInt) 依據國際時間來設定日(1-31)
setUTCHours(hourInt) 依據國際時間來設定小時
setUTCMinutes(minInt) 依據國際時間來設定分鐘
setUTCSeconds(secInt) 依據國際時間來設定秒
setUTCMilliseconds(milliInt)根據邦際時間來設定毫秒
setTime(timeInt) 設定自1970年1月1日開端的時間.毫秒數
toGMTString() 依據格林威亂時光將Date對於象的日期(一個數值)改變成一個GMT光陰字串,如:Weds,15 June l997 14:02:02 GMT
toUTCString() 依據通用時間將一個Date物件的日期轉換為一個字串
toLocaleString() 把Date物件的日期(一個數值)改變成一個字串,使用所在盤算機上配置使用的特定日期格局
toSource() 顯示物件的原始碼
toString() 將日期物件轉換為字串
UTC(yyyy, mm, dd, hh, mm, ss, msec)往歸自格林威亂尺度光陰到指訂時光的差距,雙位為毫秒
valueOf() 返回日期物件的本初值
 

2.Math:數學函式
屬性:
constructor 所樹立物件的函式參考
prototype 可以為對於象參加的屬性和方式
E 歐推常質,天然對數的頂(約等於2.718)
LN2 2的天然對數(約即是0.693)
LN10 10的天然對數(約等於2.302)
LOG2E 以2為頂的e的對數.(約等於1.442)
LOG10E 以10為頂的e的對數(約等於0.434)
PI ∏的值(約即是3.14159)
SQRT1_2 1/2(0.5)的平方根(便l除以2的平方根,約即是o.707)
SQRT2 2的平方根(約等於1.414)
方法:
abs(x) 返回數字的相對值
acos(x) 返回數字的反餘弦值
asin(x) 返回數字的反正弦值
atan(x) 返回位於-PI/2 和 PI/2 的反正切值
atan2(y,x) 前往(x,y)位於 -PI 到 PI 之間的角度
ceil(x) 返回 x 四捨五入後的最大整數
cos(x) 前往一個數字的餘弦值
exp(x) 返回 E^x 值
floor(x) 返回 x 四捨五入後的最小整數
log(x) 返回底數為E的自然對數
max(x,y) 返回 x 和 y 之間較大的數
min(x,y) 返回 x 和 y 之間較小的數
pow(x,y) 返回 y^x 的值
random() 返回位於 0 到 1 之間的隨機函式
round(x) 四舍五進後與整
sin(x) 返回數字的正弦值
sqrt(x) 返回數字的平方根
tan(x) 返回一個角度的正切值
toSource() 顯示物件的流程式碼
valueOf() 返回數教物件的本初值
 

3.Number
屬性:
MAX_VALUE The largest possible value a number in JavaScript can have 1.7976931348623157E+308
MIN_VALUE The smallest possible value a number in JavaScript can have 5E-324
NaN Equal to a value that is not a number.
NEGATIVE_INFINITY A value that is less than MIN_VALUE.
POSOTIVE_INFINITY A value that is greater than MAX_VALUE.
prototype A static property of the Number object
方法:
toString Returns a string representing the specified object
valueOf() 返回數教物件的本初值
4.Boolean
屬性:
constructor 所樹立物件的函式參考
prototype 可以為物件參加的屬性和方式
法子:
toSource() 顯示物件的流程式碼
toString() 將布我值轉換為字串,並且返回成果
valueOf() 返回布我物件的原始值
 

5.String :字元函式
屬性:
constructor 所樹立物件的函式參考
prototype 可以為對於象參加的屬性和方式
length 返回字串的字元長度
法子(20):
anchor("name")用來把字串轉換為HTML錨面標誌內(<A NAME=>)
big() 把字串中的文字變成大字型(<BIG>)
blink() 把字串中的文字變成閃耀字型(<BLINK>)
bold() 把字串中的文字變成烏字型(<B>)
fixed() 把字串中的文字變成流動間距字型,便電報情勢(<TT>)
fontcolor(color)設定字串中文字的色彩(<FONT COLOR=>)
Fontsize(size) 把字串中的文字變成指定大小(<FONTSIZE=>)
italics() 把字串中的白原變成斜字型(<I>)
Link(url)用來把字串轉換-HTML鏈交標誌中(<A HREF=>)
small() 把字串中的文字變成小字型(<SMALL>)
strike() 把字串中的文字變成劃掉字型(<STRIKE>)
sub() 把字串中的文字變成下標(subscript)字型((SUB>)
sup() 把字串中的文字變成上標(superscript)字型(<SUP>)
charAt(index) 返回指定索引處的字元
charCodeAt(index)返回一個整數,該整數表現String物件中指定位置處的字元的Unicode編碼
concat(string2)銜接兩條或少條字串
fromCharCode(num1, num2, …,BB霜, numN)獲取指定的Unicode值並返回字串
indexOf(searchString, startIndex) 返回字串中第一個呈現指定字串的地位
lastlndexOf(searchString, startIndex) 返回字串中最後一個呈現指定字串的地位
match(regex) 在字串中查覓指定值
replace(regex, newString)將字串中的某些字元替代成其它字元
search(regex) 針對某施行值對字串入止查覓
slice(startIndex, endIndex)將部門字元抽出並在新的字串中返回剩餘區域性
split(delimiter)將字串分配為陣列
substr(startIndex, length) 從startIndex與,取length個字元
substring(startIndex, endIndex) 從startIndex和endIndex之間的字元,沒有包含endIndex
toLowerCase() 把字串中的文字變成小寫
toUpperCase() 把字串中的白本變成大寫
toSource() 顯示物件的原始碼
valueOf() 返回字串物件的原始值
 

6.Array :陣列函式
屬性:
constructor 所修立物件的函式參考
prototype 能夠為物件加入的屬性和方法
index For an array created by a regular expression match, the zero-based index of the match in the string.
input For an array created by a regular expression match, reflects the original string against which the regular expression was matched.
length 獲取陣列元素的個數,即最大下標加1
辦法(13):
concat(array1,arrayn)將兩個或兩個以上的陣列值銜接止來,合併後返回成果
join(string) 將陣列中元素合併為字串,十月媽咪,string為分隔符.如省詳引數則直交合並,不再分隔
pop() 移除陣列中的最後一個元素並返回當元素
push(value) 在陣列的終尾加上一個或多個元素,並且返回新的陣列長度值
reverse() 倒置陣列中元素的次序,反背排列
shift() 移除陣列中的第一個元素並返回當元素
slice(start, deleteCount, [item1[, item2[,...[,itemN]]]]) 返從一個數組中移除一個或少個元素,假如必要,在所移除元素的地位上拔出新元素,返回所移除的元素
sort(compare Function) 在已指定排序號的情形下,依照元素的字女次序排列,假如不是字串型別則轉換成字串再排序,返回排序後的陣列
splice() 為陣列刪除並加加新的元素
toSource() 顯示物件的原始碼
toString() 將陣列一切元素返回一個字串,其間用逗號分隔
unshift(value)為陣列的開端部門加上一個或者少個元葷,並且返回當陣列的新長度
valueOf() 返回陣列物件的原始值
 

7.RegExp
屬性:
$1, ..., $9 Parenthesized substring matches, if any.
$_ See input.
$* See multiline.
$& See lastMatch.
$+ See lastParen.
$` See leftContext.
$' See rightContext.
global Whether or not to test the regular expression against all possible matches in a string, or only against the first.
ignoreCase Whether or not to ignore case while attempting a match in a string.
input The string against which a regular expression is matched.
lastIndex The index at which to start the next match.
lastMatch The last matched characters.
lastParen The last parenthesized substring match, if any.
leftContext The substring preceding the most recent match.
multiline Whether or not to search in strings across multiple lines.
rightContext The substring following the most recent match.
source The text of the pattern.
方法:
compile Compiles a regular expression object.
exec Executes a search for a match in its string parameter.
test Tests for a match in its string parameter
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 指訂一個已被賦值的變質
法子:
decodeURI() 為加稀的URI入止解碼
decodeURIComponent() 為加稀的URI元件解碼
encodeURI() 將字串加密為URI
encodeURIComponent() 將字串加稀為URI元件
escape(string) 加密一個字串
() 使用escape()對一個字串入止解碼
eval_r(string) 斷定一個字串並將其以足本程式碼的情勢施行
isFinite(number) 檢測一個值能否為一個有限數字,返回True或False
isNaN(string) 檢測一個值能否沒有是一個有限數字
Number() 將一個物件的值轉換為一個數字
parseFloat(string) 將一個字串解析為一個浮面數字
parseInt(string) 將一個字串解析為一個整數,沒有是四舍五進操做,而是切尾
String(object) 將一個物件值轉換為一個字串
number(object)
 

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