javasript 函數(shù)_第1頁(yè)
javasript 函數(shù)_第2頁(yè)
javasript 函數(shù)_第3頁(yè)
javasript 函數(shù)_第4頁(yè)
javasript 函數(shù)_第5頁(yè)
已閱讀5頁(yè),還剩36頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、JavaScript就這么回事1:基礎(chǔ)知識(shí) 1 創(chuàng)建腳本塊 1: 2: JavaScript code goes here 3: 2 隱藏腳本代碼 1: 2: 5: 在不支持JavaScript的瀏覽器中將不執(zhí)行相關(guān)代碼 3 瀏覽器不支持的時(shí)候顯示 1: 2: Hello to the non-JavaScript browser. 3: 4 鏈接外部腳本文件 1: 5 注釋腳本 1: / This is a comment 2: document.write(“Hello”); / This is a comment 3: /* 4: All of this 5: is a comment

2、6: */ 6 輸出到瀏覽器 1: document.write(“Hello”); 7 定義變量 1: var myVariable = “some value”; 8 字符串相加 1: var myString = “String1” + “String2”; 9 字符串搜索 1: 2: 7: 10 字符串替換 1: thisVar.replace(“Monday”,”Friday”); 11 格式化字串 1: 2: ! 3: var myVariable = “Hello there”; 4: document.write(myVariable.big() + “”); 5: docum

3、ent.write(myVariable.blink() + “”); 6: document.write(myVariable.bold() + “”); 7: document.write(myVariable.fixed() + “”); 8: document.write(myVariable.fontcolor(“red”) + “”); 9: document.write(myVariable.fontsize(“18pt”) + “”); 10: document.write(myVariable.italics() + “”); 11: document.write(myVar

4、iable.small() + “”); 12: document.write(myVariable.strike() + “”); 13: document.write(myVariable.sub() + “”); 14: document.write(myVariable.sup() + “”); 15: document.write(myVariable.toLowerCase() + “”); 16: document.write(myVariable.toUpperCase() + “”); 17: 18: var firstString = “My String”; 19: va

5、r finalString = firstString.bold().toLowerCase().fontcolor(“red”); 20: / 21: 12 創(chuàng)建數(shù)組 1: 2: 11: 13 數(shù)組排序 1: 2: 11: 14 分割字符串 1: 2: 10: 15 彈出警告信息 1: 2: 5: 16 彈出確認(rèn)框 1: 2: 5: 17 定義函數(shù) 1: 2: 8: 18 調(diào)用JS函數(shù) 1: Link text 2: Link text 19 在頁(yè)面加載完成后執(zhí)行函數(shù) 1: 2: Body of the page 3: 20 條件判斷 1: 2: 7: 21 指定次數(shù)循環(huán) 1: 2: ! 3

6、: var myArray = new Array(3); 4: myArray0 = “Item 0”; 5: myArray1 = “Item 1”; 6: myArray2 = “Item 2”; 7: for (i = 0; i myArray.length; i+) 8: document.write(myArrayi + “”); 9: 10: / 11: 22 設(shè)定將來(lái)執(zhí)行 1: 2: 8: 23 定時(shí)執(zhí)行函數(shù) 1: 2: 9: 24 取消定時(shí)執(zhí)行 1: 2: 9: 25 在頁(yè)面卸載時(shí)候執(zhí)行函數(shù) 1: 2: Body of the page 3: JavaScript就這么回事2

7、:瀏覽器輸出 26 訪問(wèn)document對(duì)象 1: 2: var myURL = document.URL; 3: window.alert(myURL); 4: 27 動(dòng)態(tài)輸出HTML 1: 2: document.write(“Heres some information about this document:”); 3: document.write(“”); 4: document.write(“Referring Document: “ + document.referrer + “”); 5: document.write(“Domain: “ + document.domain

8、 + “”); 6: document.write(“URL: “ + document.URL + “”); 7: document.write(“”); 8: 28 輸出換行 1: document.writeln(“a”); 2: document.writeln(“b”); 29 輸出日期 1: 2: var thisDate = new Date(); 3: document.write(thisDate.toString(); 4: 30 指定日期的時(shí)區(qū) 1: 2: var myOffset = -2; 3: var currentDate = new Date(); 4: var

9、 userOffset = currentDate.getTimezoneOffset()/60; 5: var timeZoneDifference = userOffset - myOffset; 6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); 7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString(); 8: 31 設(shè)置日期輸出格式 1: 2: var thisDate =

10、new Date(); 3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes(); 4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate(); 5: document.write(thisTimeString + “ on “ + thisDateString); 6: 32 讀取URL參數(shù) 1: 2: var urlParts = document.URL.s

11、plit(“?”); 3: var parameterParts = urlParts1.split(“&”); 4: for (i = 0; i parameterParts.length; i+) 5: var pairParts = parameterPartsi.split(“=”); 6: var pairName = pairParts0; 7: var pairValue = pairParts1; 8: document.write(pairName + “ :“ +pairValue ); 9: 10: 你還以為HTML是無(wú)狀態(tài)的么? 33 打開一個(gè)新的document對(duì)象

12、1: 2: function newDocument() 3: document.open(); 4: document.write(“This is a New Document.”); 5: document.close(); 6: 7: 34 頁(yè)面跳轉(zhuǎn) 1: 2: window.location = “”; 3: 35 添加網(wǎng)頁(yè)加載進(jìn)度窗口 1: 2: 3: 4: var placeHolder = window.open(holder.html,placeholder,width=200,height=200); 5: 6: The Main Page 7: 8: 9: This is

13、 the main page 10: 11: JavaScript就這么回事3:圖像 36 讀取圖像屬性 1: 2: Width 3: 37 動(dòng)態(tài)加載圖像 1: 2: myImage = new Image; 3: myImage.src = “Tellers1.jpg”; 4: 38 簡(jiǎn)單的圖像替換 1: 2: rollImage = new Image; 3: rollImage.src = “rollImage1.jpg”; 4: defaultImage = new Image; 5: defaultImage.src = “image1.jpg”; 6: 7: 9: 39 隨機(jī)顯示圖

14、像 1: 2: var imageList = new Array; 3: imageList0 = “image1.jpg”; 4: imageList1 = “image2.jpg”; 5: imageList2 = “image3.jpg”; 6: imageList3 = “image4.jpg”; 7: var imageChoice = Math.floor(Math.random() * imageList.length); 8: document.write(); 9: 40 函數(shù)實(shí)現(xiàn)的圖像替換 1: 2: var source = 0; 3: var replacement

15、= 1; 4: function createRollOver(originalImage,replacementImage) 5: var imageArray = new Array; 6: imageArraysource = new Image; 7: imageArraysource.src = originalImage; 8: imageArrayreplacement = new Image; 9: imageArrayreplacement.src = replacementImage; 10: return imageArray; 11: 12: var rollImage

16、1 = createRollOver(“image1.jpg”,”rollImage1.jpg”); 13: 14: 16: 17: 41 創(chuàng)建幻燈片 1: 2: var imageList = new Array; 3: imageList0 = new Image; 4: imageList0.src = “image1.jpg”; 5: imageList1 = new Image; 6: imageList1.src = “image2.jpg”; 7: imageList2 = new Image; 8: imageList2.src = “image3.jpg”; 9: image

17、List3 = new Image; 10: imageList3.src = “image4.jpg”; 11: function slideShow(imageNumber) 12: document.slideShow.src = imageListimageNumber.src; 13: imageNumber += 1; 14: if (imageNumber imageList.length) 15: window.setTimeout(“slideShow(“ + imageNumber + “)”,3000); 16: 17: 18: 19: 20: 21: 42 隨機(jī)廣告圖片

18、 1: 2: var imageList = new Array; 3: imageList0 = “image1.jpg”; 4: imageList1 = “image2.jpg”; 5: imageList2 = “image3.jpg”; 6: imageList3 = “image4.jpg”; 7: var urlList = new Array; 8: urlList0 = “http:/some.host/”; 9: urlList1 = “http:/another.host/”; 10: urlList2 = “http:/somewhere.else/”; 11: url

19、List3 = “http:/right.here/”; 12: var imageChoice = Math.floor(Math.random() * imageList.length); 13: document.write(); 14: JavaScript就這么回事4:表單 還是先繼續(xù)寫完JS就這么回事系列吧 43 表單構(gòu)成 1: 2: 3: 4: First Choice 5: Second Choice 6: 7: 8: 9: 44 訪問(wèn)表單中的文本框內(nèi)容 e);Check Text Field 45 動(dòng)態(tài)復(fù)制文本框內(nèi)容 1: 2: Enter some Text: 3: Cop

20、y Text: 4: 5: Copy Text Field 46 偵測(cè)文本框的變化 1: 2: Enter some Text: 3: 47 訪問(wèn)選中的Select 1: 2: 3: 1 4: 2 5: 3 6: 7: 8: Check Selection List 48 動(dòng)態(tài)增加Select項(xiàng) ngth+; 9: document.myForm.mySelect.optionsdocument.myForm.mySelect.length - 1.text = “3”; 10: document.myForm.mySelect.optionsdocument.myForm.mySelect.

21、length - 1.value = “Third Choice”; 11: 49 驗(yàn)證表單字段 1: 2: function checkField(field) 3: if (field.value = “”) 4: window.alert(“You must enter a value in the field”); 5: field.focus(); 6: 7: 8: 9: 10: Text Field: 11: 12: 50 驗(yàn)證Select項(xiàng) 1: function checkList(selection) 2: if (selection.length = 0) 3: windo

22、w.alert(“You must make a selection from the list.”); 4: return false; 5: 6: return true; 7: 51 動(dòng)態(tài)改變表單的action 1: 2: Username: 3: Password: 4: 5: 6: 7: 52 使用圖像按鈕 1: 2: Username: 3: Password: 4: 5: 6: 53 表單數(shù)據(jù)的加密 1: 2: ! 3: function encrypt(item) 4: var newItem = ; 5: for (i=0; i item.length; i+) 6: new

23、Item += item.charCodeAt(i) + .; 7: 8: return newItem; 9: 10: function encryptForm(myForm) 11: for (i=0; i 17: 18: 19: Enter Some Text: 20: JavaScript就這么回事5:窗口和框架 54 改變?yōu)g覽器狀態(tài)欄文字提示 1: 2: window.status = “A new status message”; 3: 55 彈出確認(rèn)提示框 1: 2: var userChoice = window.confirm(“Click OK or Cancel”); 3

24、: if (userChoice) 4: document.write(“You chose OK”); 5: else 6: document.write(“You chose Cancel”); 7: 8: 56 提示輸入 1: 2: var userName = mpt(“Please Enter Your Name”,”Enter Your Name Here”); 3: document.write(“Your Name is “ + userName); 4: 57 打開一個(gè)新窗口 1: /打開一個(gè)名稱為myNewWindow的瀏覽器新窗口 2: 3: wind

25、ow.open(“”,”myNewWindow”); 4: 58 設(shè)置新窗口的大小 1: 2: window.open(“”,”myNewWindow”,height=300,width=300); 3: 59 設(shè)置新窗口的位置 1: 2: window.open(“”,”myNewWindow”,height=300,width=300,left=200,screenX=200,top=100,screenY=100); 3: 60 是否顯示工具欄和滾動(dòng)欄 1: 2: window.open(“http: 61 是否可以縮放新窗口的大小 1: 2: window.open( , myNewW

26、indow, resizable=yes ); 62 加載一個(gè)新的文檔到當(dāng)前窗口 1: Open New Document 63 設(shè)置頁(yè)面的滾動(dòng)位置 1: 2: if (document.all) /如果是IE瀏覽器則使用scrollTop屬性 3: document.body.scrollTop = 200; 4: else /如果是NetScape瀏覽器則使用pageYOffset屬性 5: window.pageYOffset = 200; 6: 64 在IE中打開全屏窗口 1: a href=# onClick=”window.open( a full-screen window 65

27、 新窗口和父窗口的操作 1: 2: /定義新窗口 3: var newWindow = window.open(“128a.html”,”newWindow”); 4: newWindow.close(); /在父窗口中關(guān)閉打開的新窗口 5: 6: 在新窗口中關(guān)閉父窗口 7: window.opener.close() 66 往新窗口中寫內(nèi)容 1: 2: var newWindow = window.open(“”,”newWindow”); 3: newWindow.document.open(); 4: newWindow.document.write(“This is a new win

28、dow”); 5: newWIndow.document.close(); 6: 67 加載頁(yè)面到框架頁(yè)面 1: 2: 3: 4: 5: 在frame1中加載frame2中的頁(yè)面 6: parent.frame2.document.location = “135b.html”; 68 在框架頁(yè)面之間共享腳本 如果在frame1中html文件中有個(gè)腳本 1: function doAlert() 2: window.alert(“Frame 1 is loaded”); 3: 那么在frame2中可以如此調(diào)用該方法 1: 2: This is frame 2. 3: 69 數(shù)據(jù)公用 可以在框架頁(yè)

29、面定義數(shù)據(jù)項(xiàng),使得該數(shù)據(jù)可以被多個(gè)框架中的頁(yè)面公用 1: 2: var persistentVariable = “This is a persistent value”; 3: 4: 5: 6: 7: 這樣在frame1和frame2中都可以使用變量persistentVariable 70 框架代碼庫(kù) 根據(jù)以上的一些思路,我們可以使用一個(gè)隱藏的框架頁(yè)面來(lái)作為整個(gè)框架集的代碼庫(kù) 1: 2: 3: 4: 5: 教程:事半功倍系列之javascript From:向東IT博客 本文由經(jīng)典論壇 鄧永炎 整理 清華大學(xué)出版的事半功倍系列 javascript,本人照著書敲出來(lái)的,有些翻譯了一下.前幾

30、年看了一下,最近無(wú)事,重新翻了翻,很有幫助.本書應(yīng)該有光盤的,但學(xué)校的書,光盤不知在哪.希望對(duì)你學(xué) javascript有幫助 第一章javascript簡(jiǎn)介 1.在地址欄輸入javascript語(yǔ)句 Javascript:Document.write(顯示文字) 2.將javascript嵌入 HTML文檔 document.bgColor=blue 第二章 使用變量和數(shù)組 1.聲明變量 Var answer1,answer2,answer3,answer4; answer1=9; answer2=2.5 answer3=Milkey May answer4=true 2.使用整數(shù) var decimalNum,hexadecimalNum,octalNum decimalNum=24 hexadecimalNum=024 octalNum=024 document.write(顯示十進(jìn)制數(shù):+ decimalNum+) document.write(顯示十六進(jìn)制數(shù):+ hexadecimalNum +) document.write(顯示八進(jìn)制數(shù):+ octalNum +) 3.使用浮點(diǎn)數(shù) script l4.使用布爾值

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論