javascript函數(shù)大全

字號:


    列舉了javascript地常用函數(shù),并且給予了中文解釋
    1.document.write();為 輸出語句
    2.js中地注釋為//
    3.傳統(tǒng)地html文檔順序是:document->html->(head,body)
    4.一個瀏覽器窗口中地dom順序是:window->(navigator,screen,history,location,document)
    5.的到表單中元素地名稱和值:document.getelementbyid(表單中元素地id號).name(或value)
    6.一個小寫轉(zhuǎn)大寫地js: document.getelementbyid(output).value = document.getelementbyid(input).value.touppercase();
    7.js中地值類型:string,number,boolean,null,object,function
    8.js中地字符型轉(zhuǎn)換成數(shù)值型:parseint(),parsefloat()
    9.js中地數(shù)字轉(zhuǎn)換成字符型:(+變量)
    10.js中地取字符串長度是:(length)
    11.js中地字符與字符相連接使用+號.
    12.js中地比較操作符有:==等于,!=不等于,>,>=,<.<=
    13.js中聲明變量使用:var來進(jìn)行聲明
    14.js中地判斷語句結(jié)構(gòu):if(condition){}else{}
    15.js中地循環(huán)結(jié)構(gòu):for([initial expression];[condition];[upadte expression]) {inside loop}
    16.循環(huán)中止地命令是:break
    17.js中地函數(shù)定義:function functionname([parameter],...){statement[s]}
    18.當(dāng)文件中出現(xiàn)多個form表單時.可以用document.forms[0],document.forms[1]來代替.
    19.窗口:打開窗口window.open(), 關(guān)閉一個窗口:window.close(), 窗口本身:self
    20.狀態(tài)欄地設(shè)置:window.status=字符;
    21.彈出提示信息:window.alert(字符);
    22.彈出確認(rèn)框:window.confirm();
    23.彈出輸入提示框:window.prompt();
    24.指定當(dāng)前顯示鏈接地位置:window.location.href=url
    25.取出窗體中地所有表單地數(shù)量:document.forms.length
    26.關(guān)閉文檔地輸出流:document.close();
    27.字符串追加連接符:+=
    28.創(chuàng)建一個文檔元素:document.createelement(),document.createtextnode()
    29.的到元素地方法:document.getelementbyid()
    30.設(shè)置表單中所有文本型地成員地值為空:
    var form = window.document.forms[0]
    for (var i = 0; i<form.elements.length;i++){
    if (form.elements[i].type == text){
    form.elements[i].value = ;
    }
    }
    31.復(fù)選按鈕在js中判斷是否選中:document.forms[0].checkthis.checked (checked屬性代表為是否選中返回true或false)
    32.單選按鈕組(單選按鈕地名稱必須相同):取單選按鈕組地長度document.forms[0].groupname.length
    33.單選按鈕組判斷是否被選中也是用checked.
    34.下拉列表框地值:document.forms[0].selectname.options[n].value (n有時用下拉列表框名稱加上.selectedindex來確定被選中地值)
    35.字符串地定義:var mystring = new string(this is lightsword);
    36.字符串轉(zhuǎn)成大寫:string.touppercase(); 字符串轉(zhuǎn)成小寫:string.tolowercase();
    37.返回字符串2在字符串1中出現(xiàn)地位置:string1.indexof(string2)!=-1則說明沒找到.
    38.取字符串中指定位置地一個字符:stringa.charat(9);
    39.取出字符串中指定起點(diǎn)和終點(diǎn)地子字符串:stringa.substring(2,6);
    40.數(shù)學(xué)函數(shù):math.pi(返回圓周率),math.sqrt2(返回開方),math.max(value1,value2)返回兩個數(shù)中地最在值,math.pow(value1,10)返回value1地十次方,math.round(value1)四舍五入函數(shù),math.floor(math.random()*(n+1))返回隨機(jī)數(shù)
    41.定義日期型變量:var today = new date();
    42.日期函數(shù)列表:dateobj.gettime()的到時間,dateobj.getyear()的到年份,dateobj.getfullyear()的到四位地年份,dateobj.getmonth()的到月份,dateobj.getdate()的到日,dateobj.getday()的到日期幾,dateobj.gethours()的到小時,dateobj.getminutes()的到分,dateobj.getseconds()的到秒,dateobj.settime(value)設(shè)置時間,dateobj.setyear(val)設(shè)置年,dateobj.setmonth(val)設(shè)置月,dateobj.setdate(val)設(shè)置日,dateobj.setday(val)設(shè)置星期幾,dateobj.sethours設(shè)置小時,dateobj.setminutes(val)設(shè)置分,dateobj.setseconds(val)設(shè)置秒 [注意:此日期時間從0開始計]
    43.frame地表示方式: [window.]frames[n].objfuncvarname,frames[framename].objfuncvarname,framename.objfuncvarname
    44.parent代表父親對象,top代表最頂端對象
    45.打開子窗口地父窗口為:opener
    46.表示當(dāng)前所屬地位置:this
    47.當(dāng)在超鏈接中調(diào)用js函數(shù)時用:(javascript:)來開頭后面加函數(shù)名
    48.在老地瀏覽器中不執(zhí)行此js:<!-- //-->
    49.引用一個文件式地js:<script type=text/javascript src=aaa.js></script>
    50.指定在不支持腳本地瀏覽器顯示地html:<noscript></noscript>
    51.當(dāng)超鏈和onclick事件都有時,則老版本地瀏覽器轉(zhuǎn)向a.html,否則轉(zhuǎn)向b.html.例:<a href=a.html onclick=location.href='b.html';return false>dfsadf</a>
    52.js地內(nèi)建對象有:array,boolean,date,error,evalerror,function,math,number,object,rangeerror,referenceerror,regexp,string,syntaxerror,typeerror,urierror
    53.js中地?fù)Q行:\n
    54.窗口全屏大小:<script>function fullscreen(){ this.moveto(0,0);this.outerwidth=screen.availwidth;this.outerheight=screen.availheight;}window.maximize=fullscreen;</script>
    55.js中地all代表其下層地全部元素
    56.js中地焦點(diǎn)順序:document.getelementbyid(表單元素).tabindex = 1
    57.innerhtml地值是表單元素地值:如<p id=para>how are <em>you</em></p>,則innerhtml地值就是:how are <em>you</em>
    58.innertext地值和上面地一樣,只不過不會把<em>這種標(biāo)記顯示出來.
    59.contenteditable可設(shè)置元素是否可被修改,iscontenteditable返回是否可修改地狀態(tài).
    60.isdisabled判斷是否為禁止?fàn)顟B(tài).disabled設(shè)置禁止?fàn)顟B(tài)
    61.length取的長度,返回整型數(shù)值
    62.addbehavior()是一種js調(diào)用地外部函數(shù)文件其擴(kuò)展名為.htc
    63.window.focus()使當(dāng)前地窗口在所有窗口之前.
    64.blur()指失去焦點(diǎn).與focus()相反.
    65.select()指元素為選中狀態(tài).
    66.防止用戶對文本框中輸入文本:onfocus=this.blur()
    67.取出該元素在頁面中出現(xiàn)地數(shù)量:document.all.tags(div(或其它html標(biāo)記符)).length
    68.js中分為兩種窗體輸出:模態(tài)和非模態(tài).window.showmodaldialog(),window.showmodeless()
    69.狀態(tài)欄文字地設(shè)置:window.status='文字',默認(rèn)地狀態(tài)欄文字設(shè)置:window.defaultstatus = '文字.';
    70.添加到收藏夾:external.addfavorite(http://www.ynpxrz.com,jaskdlf);
    71.js中遇到腳本錯誤時不做任何操作:window.onerror = donothing; 指定錯誤句柄地語法為:window.onerror = handleerror;
    72.js中指定當(dāng)前打開窗口地父窗口:window.opener,支持opener.opener...地多重繼續(xù).
    73.js中地self指地是當(dāng)前地窗口
    74.js中狀態(tài)欄顯示內(nèi)容:window.status=內(nèi)容
    75.js中地top指地是框架集中最頂層地框架
    76.js中關(guān)閉當(dāng)前地窗口:window.close();
    77.js中提出是否確認(rèn)地框:if(confirm(are you sure?)){alert(ok);}else{alert(not ok);}
    78.js中地窗口重定向:window.navigate(http://www.ynpxrz.com);
    79.js中地打印:window.print()
    80.js中地提示輸入框:window.prompt(message,defaultreply);
    81.js中地窗口滾動條:window.scroll(x,y)
    82.js中地窗口滾動到位置:window.scrollby
    83.js中設(shè)置時間間隔:setinterval(expr,msecdelay)或setinterval(funcref,msecdelay)或settimeout
    84.js中地模態(tài)顯示在ie4+行,在nn中不行:showmodaldialog(url[,arguments][,features]);
    85.js中地退出之前使用地句柄:function verifyclose(){event.returnvalue=we really like you and hope you will stay longer.;}} window.onbeforeunload=verifyclose;
    86.當(dāng)窗體第一次調(diào)用時使用地文件句柄:onload()
    87.當(dāng)窗體關(guān)閉時調(diào)用地文件句柄:onunload()
    88.window.location地屬性: protocol(http:),hostname(,指跳轉(zhuǎn)到相應(yīng)地錨記),href(全部地信息)
    89.window.location.reload()刷新當(dāng)前頁面.
    89-1.parent.location.reload()刷新父親對象(用于框架)
    89-2.opener.location.reload()刷新父窗口對象(用于單開窗口)
    89-3.top.location.reload()刷新最頂端對象(用于多開窗口)
    90.window.history.back()返回上一頁,window.history.forward()返回下一頁,window.history.go(返回第幾頁,也可以使用訪問過地url)
    91.document.write()不換行地輸出,document.writeln()換行輸出
    92.document.body.nowrap=true;防止鏈接文字折行.
    93.變量名.charat(第幾位),取該變量地第幾位地字符.
    94.abc.charcodeat(第幾個),返回第幾個字符地ascii碼值.
    95.字符串連接:string.concat(string2),或用+=進(jìn)行連接
    96.變量.indexof(字符,起始位置),返回第一個出現(xiàn)地位置(從0開始計算)
    97.string.lastindexof(searchstring[,startindex])最后一次出現(xiàn)地位置.
    98.string.match(regexpression),判斷字符是否匹配.
    99.string.replace(regexpression,replacestring)替換現(xiàn)有字符串.
    100.string.split(分隔符)返回一個數(shù)組存儲值.
    101.string.substr(start[,length])取從第幾位到指定長度地字符串.
    102.string.tolowercase()使字符串全部變?yōu)樾?
    103.string.touppercase()使全部字符變?yōu)榇髮?
    104.parseint(string[,radix(代表進(jìn)制)])強(qiáng)制轉(zhuǎn)換成整型.
    105.parsefloat(string[,radix])強(qiáng)制轉(zhuǎn)換成浮點(diǎn)型.
    106.isnan(變量):測試是否為數(shù)值型.
    107.定義常量地關(guān)鍵字:const,定義變量地關(guān)鍵字:var