DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> js寶典學習筆記(上)
js寶典學習筆記(上)
編輯:JavaScript基礎知識     
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<form.elements.length;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:<!--     //-->
49.引用一個文件式的JS:<script type="text/javascript" src="aaa.js"></script>
50.指定在不支持腳本的浏覽器顯示的HTML:<noscript></noscript>
51.當超鏈和ONCLICK事件都有時,則老版本的浏覽器轉向a.html,否則轉向b.html.例:<a href="a.html" onclick="location.href=’b.html’;return false">dfsadf</a>
52.JS的內建對象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53.JS中的換行:\n
54.窗口全屏大小:<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>
55.JS中的all代表其下層的全部元素
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved