一、基礎(chǔ)
向文檔中輸出文本:<script>document.write("Hello Javascript");</script>。script標(biāo)簽可以放在html的任何地方,一般建議放在head標(biāo)簽里。如果有多段script代碼,會(huì)按照從上到下,順序執(zhí)行。外部:<html><script src="d/hello.js"></script></html>
變量:var x = 1;
調(diào)試辦法:alert、瀏覽器
基本數(shù)據(jù)類型:undefined、Boolean、Number、String、var、typeof、null
類型轉(zhuǎn)換:偽對(duì)象概念:javascript是一門很有意思的語(yǔ)言,即便是基本類型,也是偽對(duì)象,所以他們都有屬性和方法。無(wú)論是Number,Boolean還是String都有一個(gè)toString方法,用于轉(zhuǎn)換為字符串。parseInt()和parseFloat(),可以轉(zhuǎn)換為數(shù)字。使用內(nèi)置函數(shù)Boolean() 轉(zhuǎn)換為Boolean值。
函數(shù):function print(){document.write("這一句話是由一個(gè)自定義函數(shù)打印");}print();
事件:javascript允許html與用戶交互的行為。 用戶任何對(duì)網(wǎng)頁(yè)的操作,都會(huì)產(chǎn)生一個(gè)事件。事件有很多種,比如鼠標(biāo)移動(dòng),鼠標(biāo)點(diǎn)擊,鍵盤點(diǎn)擊等等。
算數(shù)運(yùn)算符:+-*/
邏輯運(yùn)算符:==、!=、>、>=、<、<=、===、!==、?:
條件語(yǔ)句:if-else、switch
循環(huán)語(yǔ)句: for, while, do-while, for-each
錯(cuò)誤處理:try catch
對(duì)象: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)。自定義對(duì)象:通過(guò)function設(shè)計(jì),通過(guò)prototype實(shí)現(xiàn)增加新方法。
二、BOM
BOM:瀏覽器對(duì)象模型(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
計(jì)時(shí)器:setTimeout、setInterval、clearInterval、document.write()