一、基礎
向文檔中輸出文本:<script>document.write("Hello Javascript");</script>。script標簽可以放在html的任何地方,一般建議放在head標簽里。如果有多段script代碼,會按照從上到下,順序執行。外部:<html><script src="d/hello.js"></script></html>
變量:var x = 1;
調試辦法:alert、瀏覽器
基本數據類型:undefined、Boolean、Number、String、var、typeof、null
類型轉換:偽對象概念:javascript是一門很有意思的語言,即便是基本類型,也是偽對象,所以他們都有屬性和方法。無論是Number,Boolean還是String都有一個toString方法,用于轉換為字符串。parseInt()和parseFloat(),可以轉換為數字。使用內置函數Boolean() 轉換為Boolean值。
函數:function print(){document.write("這一句話是由一個自定義函數打印");}print();
事件:javascript允許html與用戶交互的行為。 用戶任何對網頁的操作,都會產生一個事件。事件有很多種,比如鼠標移動,鼠標點擊,鍵盤點擊等等。
算數運算符:+-*/
邏輯運算符:==、!=、>、>=、<、<=、===、!==、?:
條件語句:if-else、switch
循環語句: for, while, do-while, for-each
錯誤處理:try catch
對象:Number(new Number、MIN_VALUE、MAX_VALUE、Nan、toFixed、toExponential、valueOf)、String(new String()、length、charAtcharCodeAt、concat、indexOf lastIndexOf、localeCompare、substring、split、replace、charAt、concat、substring)、Date(new Date、getFullYear、getMonth、getDate、getHours、getMinutes、getSeconds、getMilliseconds、getDay、getTime、setFullYear、setMonth、setDate、setHours、setMinutes、setSeconds)、Array(new Array、length、for、for in、concat、join、push pop、unshift shift、sort)、Math(E PI、abs、min、max、pow、round、random)。自定義對象:通過function設計,通過prototype實現增加新方法。
二、BOM
BOM:瀏覽器對象模型(Browser Object Model)。包括Window、Navigator、Screen、History、Location
Window:innerWidth、innerHeight、outerWidth、outerHeight、open
Navigator:appName、appVersion、appCodeName、platform、cookieEnabled、userAgent
Screen:width、availwidth
History:back、go(-2)
Location:reload、assign("/")、protocol、hostname、port、host、pathname、hash、search
彈出框:alert、confirm、prompt
計時器:setTimeout、setInterval、clearInterval、document.write()