一舱呻、基礎(chǔ)
向文檔中輸出文本:<script>document.write("Hello Javascript");</script>癌蓖。script標(biāo)簽可以放在html的任何地方,一般建議放在head標(biāo)簽里奄薇。如果有多段script代碼,會按照從上到下抗愁,順序執(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)換:偽對象概念:javascript是一門很有意思的語言,即便是基本類型倘潜,也是偽對象绷柒,所以他們都有屬性和方法。無論是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與用戶交互的行為。 用戶任何對網(wǎng)頁的操作澜掩,都會產(chǎn)生一個(gè)事件购披。事件有很多種,比如鼠標(biāo)移動肩榕,鼠標(biāo)點(diǎn)擊刚陡,鍵盤點(diǎn)擊等等。
算數(shù)運(yùn)算符:+-*/
邏輯運(yùn)算符:==株汉、!=筐乳、>、>=乔妈、<蝙云、<=、===路召、!==勃刨、?:
條件語句:if-else、switch
循環(huán)語句: for, while, do-while, for-each
錯(cuò)誤處理: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設(shè)計(jì)逗宜,通過prototype實(shí)現(xiàn)增加新方法雄右。
二空骚、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
計(jì)時(shí)器:setTimeout痰腮、setInterval、clearInterval律罢、document.write()