js 常用語句

  1. document.write(" "); 輸出語句
  2. JS 中的注釋為 //
  3. 傳統(tǒng)的 HTML 文檔順序是: document- >html- >(head,body)
  4. 一個(gè)瀏覽器窗口中的 DOM 順序是: window- >(navigator,screen,history,location,document)
  5. 得到表單中元素的名稱和值:document.getElementById( "表單中元素的ID號(hào) ").name(或value)
  6. 一個(gè)小寫轉(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 中的字符與字符相連接使用號(hào).
  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)多個(gè) form 表單時(shí).可以用document.forms[0],document.forms[1]來代替.
  19. 窗口:打開窗口window.open(), 關(guān)閉一個(gè)窗口: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)建一個(gè)文檔元素: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.type == "text "){
    form.elements.value = " ";
    }
}
  1. 復(fù)選按鈕在 JS 中判定是否選中:document.forms[0].checkThis.checked (checked 屬性代表為是否選中返回 TRUE 或 FALSE)

  2. 單選按鈕組(單選按鈕的名稱必須相同):取單選按鈕組的長度document.forms[0].groupName.length

  3. 單選按鈕組判定是否被選中也是用 checked.

  4. 下拉列表框的值:document.forms[0].selectName.options[n].value (n 有時(shí)用下拉列表框名稱加上.selectedIndex 來確定被選中的值)

  5. 字符串的定義:var myString = new String( "This is lightsword ");

  6. 字符串轉(zhuǎn)成大寫:string.toUpperCase(); 字符串轉(zhuǎn)成小寫:string.toLowerCase();

  7. 返回字符串 2 在字符串 1 中出現(xiàn)的位置:String1.indexOf( "String2 ")!=-1 則說明沒找到.

  8. 取字符串中指定位置的一個(gè)字符:StringA.charAt(9);

  9. 取出字符串中指定起點(diǎn)和終點(diǎn)的子字符串:stringA.substring(2,6);

  10. 數(shù)學(xué)函數(shù):Math.PI(返回圓周率),Math.SQRT2(返回開方),Math.max(value1,value2)返回兩個(gè)數(shù)中的最在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函數(shù),Math.floor(Math.random()*(n 1))返回隨機(jī)數(shù)

  11. 定義日期型變量:var today = new Date();

  12. 日期函數(shù)列表:dateObj.getTime()得到時(shí)間,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期幾,dateObj.getHours()得到小時(shí),dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTime(value)設(shè)置時(shí)間,dateObj.setYear(val)設(shè)置年,dateObj.setMonth(val)設(shè)置月,dateObj.setDate(val)設(shè)置日,dateObj.setDay(val)設(shè)置星期幾,dateObj.setHours 設(shè)置小時(shí),dateObj.setMinutes(val)設(shè)置分,dateObj.setSeconds(val)設(shè)置秒 [注重:此日期時(shí)間從 0 開始計(jì)]

  13. FRAME 的表示方式: [window.]frames[n].ObjFuncVarName,frames[ "frameName "].ObjFuncVarName,frameName.ObjFuncVarName

  14. parent 代表父親對象,top 代表最頂端對象

  15. 打開子窗口的父窗口為:opener

  16. 表示當(dāng)前所屬的位置:this

  17. 當(dāng)在超鏈接中調(diào)用 JS 函數(shù)時(shí)用:(javascript :)來開頭后面加函數(shù)名

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容