本文由經(jīng)典論壇 鄧永炎 整理
清華大學(xué)出版的《事半功倍系列 javascript》,本人照著書敲出來的,有些翻譯了一下.前幾年看了一下,最近無事,重新翻了翻,很有幫助.本書應(yīng)該有光盤的,但學(xué)校的書,光盤不知在哪.希望對你學(xué) javascript有幫助
第一章javascript簡介
1.在地址欄輸入javascript語句
Javascript:Document.write("顯示文字")
2.將javascript嵌入 HTML文檔
<script language=javascript> document.bgColor="blue" </script>
第二章 使用變量和數(shù)組
1.聲明變量
<script language=javascripe> Var answer1,answer2,answer3,answer4; answer1=9; answer2=2.5 answer3="Milkey May" answer4=true </script>
2.使用整數(shù)
<script language=javascript> var decimalNum,hexadecimalNum,octalNum decimalNum=24 hexadecimalNum=0x24 octalNum=024 document.write("顯示十進制數(shù):"+ decimalNum+"<br>") document.write("顯示十六進制數(shù):"+ hexadecimalNum +"<br>") document.write("顯示八進制數(shù):"+ octalNum +"<br>") </script>
3.使用浮點數(shù)
<script language=javascript> var num1,num2,num3,num4 num1=1234567890000.0 num2=5.14e23 num3=0.0000123456 num4=6.0254e3-4 document.write("浮點數(shù)1:"+num1+"<br>") document.write("浮點數(shù)2:"+num2+"<br>") document.write("浮點數(shù)3:"+num3+"<br>") document.write("浮點數(shù)4:"+num4+"<br>") </script>
4.使用布爾值
<script language=javascript> var answer1,answer2 answer1=true answer2=false document.write("顯示布爾1:"+answer1+"<br>") document.write("顯示布爾2:"+answer2+"<br>") </script>
5.使用字符串
<script language=javascript> var str1,str2 str1="fdsgdg dsfdsf china" str2="武漢市廣播電視大學(xué)" document.write("顯示字符串1:"+str1+"<br>") document.write("顯示字符串2:"+str2+"<br>") </script>
6.確定變量類型
<script> var answer1,answer2,answer3,answer4 answer1=9 answer2=2.5 answer3="milky may" answer4=true document.write("變量1的類型是:"+typeof answer1 +"<br>") document.write("變量2的類型是:"+typeof answer2 +"<br>") document.write("變量3的類型是:"+typeof answer3 +"<br>") document.write("變量4的類型是:"+typeof answer4 +"<br>") </script>
7.將字符串轉(zhuǎn)換成數(shù)字
<script> var str1="31 days in january" var int1=parseInt(str1) document.write("str1的數(shù)據(jù)類型是 :"+typeof str1+"<br>") document.write("int1的數(shù)據(jù)類型是 :"+typeof int1+"<br>") </script>
8.將數(shù)字轉(zhuǎn)換成字符串
<script> var int1=256 var str1=""+int1 document.write("str1的數(shù)據(jù)類型是 :"+typeof str1+"<br>") document.write("int1的數(shù)據(jù)類型是 :"+typeof int1+"<br>") </script>
9.聲明數(shù)組
<script> array=new Array(5) array[0]=1 array[1]=3 array[2]=5 array[3]=7 array[4]=11 document.write("數(shù)組是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4]) </script>
10.確定數(shù)組元素的個數(shù)
<script> array=new Array(5) array[0]=1 array[1]=3 array[2]=5 array[3]=7 array[4]=11 document.write("數(shù)組是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4]+"<br>") document.write("數(shù)組的元素個數(shù)是"+array.length) </script>
11.將數(shù)組轉(zhuǎn)換為字符串
<script> array=new Array() array[0]="dark" array[1]="apple" array[2]="nebula" array[3]="water" str1=array.join() str2=array.join(" ") document.write(str1+"<br>") document.write(str2) </script>
12.對數(shù)組排序
<script> array=new Array() array[0]="dark" array[1]="apple" array[2]="nebula" array[3]="water" str1=array.sort() document.write(str1+"<br>") </script>
出處:藍色理想
責(zé)任編輯:moby
上一頁 下一頁 事半功倍之Javascript [2]
◎進入論壇網(wǎng)頁制作、網(wǎng)站綜合版塊參加討論
|