常用的107條Javascript

來源:互聯網
上載者:User

1.document.write( ” “); 輸出語句
2.JS中的注釋為//
3.傳統的HTML文檔順序是:document- >html- >(head,body)
4.一個瀏覽器視窗中的DOM順序是:window- >(navigator,screen,history,location,document)
5.得到表單中元素的名稱和值:document.getElementById( “表單中元素的ID號 “).name(或value)
6.一個小寫轉大寫的JS: document.getElementById( “output “).value = document.getElementById( “input “).value.toUpperCase();
7.JS中的實值型別:String,Number,Boolean,Null,Object,Function
8.JS中的字元型轉換成數值型:parseInt(),parseFloat()
9.JS中的數字轉換成字元型:( ” ” 變數)
10.JS中的取字串長度是:(length)
11.JS中的字元與字元相串連使用號.
12.JS中的比較操作符有:==等於,!=不等於, >, >=, <. <=
13.JS中聲明變數使用:var來進行聲明
14.JS中的判定語句結構:if(condition){}else{}
15.JS中的迴圈結構:for([initial expression];[condition];[upadte expression]) {inside loop}
16.迴圈中止的命令是:break
17.JS中的函數定義:function functionName([parameter],...){statement[s]}
18.當檔案中出現多個form表單時.可以用document.forms[0],document.forms[1]來代替.
19.視窗:開啟視窗window.open(), 關閉一個視窗:window.close(), 視窗本身:self
20.狀態欄的設定:window.status= "字元 ";
21.彈出提示資訊:window.alert( "字元 ");
22.彈出確認框:window.confirm();
23.彈出輸入提示框:window.prompt();
24.指定當前顯示連結的位置:window.location.href= "URL "
25.取出表單中的所有表單的數量:document.forms.length
26.關閉文檔的輸出資料流:document.close();
27.字串追加串連符: =
28.建立一個文件項目:document.createElement(),document.createTextNode()
29.得到元素的方法:document.getElementById()
30.設定表單中所有文本型的成員的值為空白:
var form = window.document.forms[0]
for (var i = 0; i
if (form.elements.type == "text "){
form.elements.value = " ";
}
}
31.複選按鈕在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.字串轉成大寫:string.toUpperCase(); 字串轉成小寫:string.toLowerCase();
37.返回字串2在字串1中出現的位置:String1.indexOf( "String2 ")!=-1則說明沒找到.
38.取字串中指定位置的一個字元:StringA.charAt(9);
39.取出字串中指定起點和終點的子字串:stringA.substring(2,6);
40.數學函數:Math.PI(返回圓周率),Math.SQRT2(返回開方),Math.max(value1,value2)返回兩個數中的最在值,Math.pow(value1,10)返回

value1的十次方,Math.round(value1)四捨五入函數,Math.floor(Math.random()*(n 1))返回隨機數
41.定義日期型變數:var today = new Date();
42.日期函數列表:dateObj.getTime()得到時間,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得

到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期幾,dateObj.getHours()得到小時,dateObj.getMinutes()得到

分,dateObj.getSeconds()得到秒,dateObj.setTime(value)設定時間,dateObj.setYear(val)設定年,dateObj.setMonth(val)設定

月,dateObj.setDate(val)設定日,dateObj.setDay(val)設定星期幾,dateObj.setHours設定小時,dateObj.setMinutes(val)設定

分,dateObj.setSeconds(val)設定秒 [注重:此日期時間從0開始計]
43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames[ "frameName "].ObjFuncVarName,frameName.ObjFuncVarName
44.parent代表父親對象,top代表最頂端對象
45.開啟子視窗的父視窗為:opener
46.表示當前所屬的位置:this
47.當在超連結中調用JS函數時用:(javascript :)來開頭後面加函數名
48.在老的瀏覽器中不執行此JS:

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.