




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上畢業(yè)設(shè)計(jì)(論文)外文資料翻譯題 目: Beginning JavaScript with DOM Scripting and Ajax 深入淺出JavaScript學(xué) 院: 信息工程學(xué)院 系 計(jì)算機(jī) 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù)班 級: 學(xué) 號: 姓 名: 指導(dǎo)教師:起訖日期:專心-專注-專業(yè)外文資料翻譯譯文深入淺出JavaScript1.1 JavaScript產(chǎn)生的原因在Web發(fā)展的初期,主要有HTML和公共管理接口(GUI)。HTML定義了大部分的文本文檔并且只是用戶代理(通常為網(wǎng)頁瀏覽器)如何顯示。比如,標(biāo)簽<p></p>之間的文字就會成
2、為一個(gè)段落,在這個(gè)段落中可以使用標(biāo)簽<h1></h1>來定義最主要的頁面標(biāo)題。注意大多數(shù)開始標(biāo)簽,都會有相應(yīng)的以</開頭的結(jié)束標(biāo)簽。HTML有一個(gè)缺點(diǎn),即他的狀態(tài)是固定不變的。如果想改變一些東西或者使用用戶輸入的數(shù)據(jù),就需要向服務(wù)器提出一個(gè)往返的請求。使用動態(tài)技術(shù)(如ColdFusion、ASP、ASP.NET、PHP或JSP)就可以從表單或者參數(shù)中將信息發(fā)送到服務(wù)器然后通過服務(wù)器完成計(jì)算、測試、數(shù)據(jù)庫查找等。與這些技術(shù)相關(guān)聯(lián)的應(yīng)用程序服務(wù)器則會產(chǎn)生一個(gè)HTML文檔來顯示結(jié)果,然后把處理的結(jié)果一HTML文檔的形式返回到瀏覽器以供用戶查看。這樣做的問題在于無論何時(shí)網(wǎng)
3、頁只要有變化,以上整個(gè)過程都需要再重復(fù)執(zhí)行一遍(并且重新加載網(wǎng)頁)。這樣會顯得比較笨重緩慢,沒有網(wǎng)絡(luò)這個(gè)新媒介對我們承諾的那么美好?,F(xiàn)在,人們已經(jīng)普遍擁有了快速的因特網(wǎng)連接。但是顯示一個(gè)頁面仍然意味著重新加載,這是一個(gè)時(shí)常失敗的緩慢過程(遇到過Error 404沒有?)。我們需要更加靈活的東西要允許Web開發(fā)人員快速地對用戶給予反饋并且不用從服務(wù)器重新加載頁面就能改變HTML??梢韵胂笥羞@么一個(gè)表單,只要有一個(gè)字段中產(chǎn)生了錯誤,它都需要重新加載,如果能夠不用重新從服務(wù)器加載頁面,就能快速地獲取錯誤提示,那豈不是更方便實(shí)用?這正是JavaScript的用武之地。一些信息(比如表單上的一些計(jì)算和驗(yàn)
4、證信息)并不需要依靠服務(wù)器。JavaScript可以由訪問者電腦上的用戶代理(通常是一個(gè)瀏覽器)來執(zhí)行。我們把這叫做客戶端代碼(client-side code)。這樣可以減少與服務(wù)器的交互成本并且使網(wǎng)站運(yùn)行得更快。1.2 JavaScript是什么JavaScript的前身是LiveScript,但是網(wǎng)景公司后來把名字改成了JavaScript,很可能是由于Java的火爆。這個(gè)名字經(jīng)常會令人感到迷惑,因?yàn)楸M管Java與JavaScript有些語法比較相近,但它們之間并沒有必然的聯(lián)系。Java之于JavaScript就好比Car(汽車)之于Carpet(地毯)。來自Usenet上的JavaSc
5、ript討論組網(wǎng)景公司在1996年創(chuàng)造了JavaScript語言,它包含在Netscape Navigator(NN)2.0瀏覽器中,用解釋器來讀取和執(zhí)行添加到.html頁面的JavaScript代碼。從此,這種語言穩(wěn)步發(fā)展壯大并越來越普及,現(xiàn)在大多數(shù)瀏覽器都支持它。這意味著JavaScript可以用于網(wǎng)頁中,被所有現(xiàn)代的瀏覽器所解釋。但是,不同的瀏覽器在實(shí)現(xiàn)JavaScript的方式上是不同的,盡管核心的JavaScript語言是一樣的。不過,JavaScript可以被用戶關(guān)閉掉,并且一些公司和機(jī)構(gòu)從安全的角度考慮要求他們的用戶這樣做。這個(gè)我們稍后(貫穿本書)會進(jìn)一步討論。關(guān)于JavaScr
6、ipt最大的特點(diǎn)就是,一旦學(xué)會了如何在瀏覽器編程中使用它,你就可以把它應(yīng)用到其他的領(lǐng)域中。微軟的服務(wù)器使用JavaScript去做服務(wù)器端網(wǎng)頁編程(ASP),PDF文件現(xiàn)在也在使用JavaScript,甚至Windows的任務(wù)管理也可以使用JavaScript來自動運(yùn)行。許多應(yīng)用程序,如Dreamweaver和Photoshop,都可以使用JavaScript來編寫腳本。操作系統(tǒng)上的許多插件,比如蘋果公司的Dashboard或者Linux和Windows平臺上的Konfabulator,甚至允許使用JavaScript編寫小的幫助程序。最近許多大公司也提供了可用在網(wǎng)頁中的JavaScript對
7、象和方法組成的API(應(yīng)用編程接口),Google Maps就是其中的一種。只需要使用幾行代碼就可以在你的網(wǎng)站中提供可縮放和可滾動的地圖。另一個(gè)更好地特點(diǎn)就是,JavaScript比高級編程語言和服務(wù)器端編程更容易開發(fā)。它不需要像Java和C+那樣編譯,也不需要像Perl、PHP或Ruby語言那樣運(yùn)行在服務(wù)器上或需要在命令行執(zhí)行。編寫、執(zhí)行、調(diào)試和應(yīng)用JavaScript腳本所需要的只是文本編輯器和瀏覽器,而這兩者在所有的操作系統(tǒng)上都提供。當(dāng)然,也有工具可以使你更加方便,如Mozilla Venkman、Microsoft Script Debugger和kjscmd這樣的JavaScript
8、調(diào)試器。1.3 JavaScript的問題和價(jià)值正如我在本章的開始提到的,JavaScript在過去的幾年里就已經(jīng)成為Web開發(fā)的一個(gè)完整的部分,但是它也經(jīng)常被錯誤地使用。結(jié)果,它就落了一個(gè)不好的名聲。導(dǎo)致這個(gè)結(jié)果的原因是某些嚴(yán)重影響用戶的JavaScript特效,如移動的頁面元素和彈出窗口。這種情況你第一次看到印象會很深刻,但很快就變成了“有了也不錯”,在有些情況下,甚至變成“沒有更好”。許多類似的效果都來自DHTML時(shí)代(相見第3章)。術(shù)語用戶代理(user agent)和對其含義的缺乏理解同樣也是一個(gè)問題。通常,用戶代理是指一個(gè)瀏覽器,比如微軟的IE,Netscape、Mozilla(M
9、oz),F(xiàn)irefox(Fx)、Opera或Safari。但是瀏覽器不是web上唯一的用戶代理,其他用戶代理還包括: 輔助技術(shù),用來幫助用戶克服它們的缺陷比如語音合成軟件或者盲文顯示器。 純文本代理,例如Lynx。 支持Web的應(yīng)用程序。 游戲控制臺。 手機(jī)。 個(gè)人數(shù)字助理(PDA)。 交互式的電視機(jī)頂盒。 搜索引擎和其他索引程序 其他這么多類的用戶代理(以及一些沒有更新的舊用戶代理),它們使用了不同的技術(shù)手段,對于JavaScript也是一個(gè)非常大的危險(xiǎn)。并不是所有的訪問者都能體驗(yàn)到你所應(yīng)用的JavaScript增強(qiáng),許多人都會出于安全的考慮關(guān)閉JavaScript。JavaScript既可
10、以用來做好事,也可以用來做壞事。如果操作系統(tǒng)(比如沒有打補(bǔ)丁的windows)語序,可以通過JavaScript來在某臺計(jì)算機(jī)上安裝病毒或木馬,或者讀取用戶信息并把它發(fā)送到另外一個(gè)服務(wù)器上。注解 沒有辦法知道訪問者在使用什么工具,他的計(jì)算機(jī)功能如何。再者,你永遠(yuǎn)不知道訪問者的經(jīng)驗(yàn)和能力如何。這也是網(wǎng)絡(luò)很好的一個(gè)方面每個(gè)人都可以參與。然而,這樣會給JavaScript程序員帶來意外的后果。在大多數(shù)情況下,你可能想要一種服務(wù)器端的替代方案。它可以測試用戶代理是否支持所需要的功能,如果不支持,服務(wù)器會使用其替代方案。腳本語言的獨(dú)立性對于網(wǎng)站是法律方面的要求,在英國的數(shù)字歧視法、美國法律的508條款和
11、世界上其他地區(qū)的法律中都有定義。這意味著如果你開發(fā)的站點(diǎn)沒有JavaScript就不能使用,或者你的JavaScript增強(qiáng)需要用戶或用戶代理在不低效運(yùn)行得情況下具有一定的能力,那么你的客戶就可以控告你歧視。然而,JavaScript既不是邪惡的也不是沒用的,它是一個(gè)優(yōu)秀的工具,可以幫助在你平滑流暢的網(wǎng)站上沖浪的用戶花費(fèi)更少的時(shí)間。外文資料原文出自Beginning JavaScript with DOM Scripting and Ajax,2006:3-6 作者:Christian HeilmannBeginning JavaScript with DOM Scripting and Aj
12、axThe Why of JavaScriptIn the beginning of the Web, there was HTML and the Common Gateway Interface (CGI). HTML defines the parts of a text document and instructs the user agent (usually the web browser) how to show itfor example, text surrounded by the tags <p></p> becomes a paragraph.
13、Within that paragraph you may have <h1></h1> tags that define the main page heading. Notice that for most opening tags, there is a corresponding closing tag that begins with </. HTML has one disadvantageit has a fixed state. If you want to change something, or use data the visitor ent
14、ered, you need to make a round-trip to a server. Using a dynamic technology (such as ColdFusion, ASP, ASP.NET, PHP, or JSP) you send the information from forms, or from parameters, to a server, which then performs calculating/testing/database lookups, etc. The application server associated with thes
15、e technologies then writes an HTML document to show the results, and the resulting HTML document is returned to the browser for viewing. The problem with that is it means every time there is a change, the entire process must be repeated (and the page reloaded). This is cumbersome, slow, and not as i
16、mpressive as the new media “Internet” promised us to be. It is true that at least the Western world has the benefit of fast Internet connections these days, but displaying a page still means a reload, which could be a slow process that frequently fails (ever get an Error 404?).We need something slic
17、kersomething that allows web developers to give immediate feedback to the user and change HTML without reloading the page from the server. Just imagine a form that needs to be reloaded every time theres an error in one of its fieldsisnt it handier when something flags the errors immediately, without
18、 needing to reload the page from the web server? This is one example of what JavaScript can do for you.Some information, such as calculations and verifying the information on a form, may not need to come from the server. JavaScript is executed by the user agent (normally a browser) on the visitors c
19、omputer. We call this client-side code. This could result in fewer trips to the server and faster-running web sites.What Is JavaScript?JavaScript started life as LiveScript, but Netscape changed the namepossibly because of the excitement being generated by Javato JavaScript. The name is confusing th
20、ough, as there is no real connection between Java and JavaScriptalthough some of the syntax looks similar.Java is to JavaScript what Car is to CarpetFrom a JavaScript discussion group on UsenetNetscape created the JavaScript language in 1996 and included it in their Netscape Navigator (NN) 2.0 brows
21、er via an interpreter that read and executed the JavaScript added to .html pages. The language has steadily grown in popularity since then, and is now supported by the most popular browsers.The good news is that this means JavaScript can be used in web pages for all major modern browsers. The not-qu
22、ite-so-good news is that there are differences in the way the different browsers implement JavaScript, although the core JavaScript language is much the same. However, JavaScript can be turned off by the userand many companies and other institutions require their users to do so for security reasons.
23、 We will discuss this furthershortly, as well as throughout this book.The great thing about JavaScript is that once youve learned how to use it for browser programming, you can move on to use it in other areas. Microsofts serverIISuses JavaScript to program server-side web pages (ASP), PDF files now
24、 use JavaScript, and even Windows administration tasks can be automated with JavaScript code. A lot of applications such as Dreamweaver and Photoshop are scriptable with JavaScript. Operating system add-ons likethe Apple Dashboard or Konfabulator on Linux and Windows even allow you to write smallhel
25、per applications in JavaScript.Lately a lot of large companies also offer application programming interfaces (APIs) that feature JavaScript objects and methods you can use in your own pagesGoogle Maps being one of them. You can offer a zoomable and scrollable map in your web site with just a few lin
26、es of code.Even better is the fact that JavaScript is a lot easier to develop than higher programming languages or server-side scripting languages. It does not need any compilation like Java or C+, or to be run on a server or command line like Perl, PHP, or Ruby: all you need to write, execute, debu
27、g, and apply JavaScript is a text editor and a browserboth of which are supplied with any operating system. There are, of course, tools that make it a lot easier for you, examples being JavaScript debuggers like Mozilla Venkman, Microsoft Script Debugger, or kjscmd.Problems and Merits of JavaScriptA
28、s I mentioned at the outset of this chapter, JavaScript has been an integral part of web development over the last few years, but it has also been used wrongly. As a result, it has gotten a bad reputation. The reason for this is gratuitous JavaScript effects, like moving page elements and pop-up win
29、dows, which might have been impressive the first time you saw them but soon turned out to be just a “nice to have” and in some cases even a “nice to not have any longer.” A lot of this comes from the days of DHTML (more on this in Chapter 3).The term user agent and the lack of understanding what a u
30、ser agent is can also be a problem. Normally, the user agent is a browser like Microsoft Internet Explorer (MSIE), Netscape, Mozilla (Moz), Firefox (Fx), Opera, or Safari. However, browsers are not the only user agents on the Web. Others include Assistive technology that helps users to overcome the
31、limitations of a disabilitylike text-to-speech software or Braille displays Text-only agents like Lynx Web-enabled applications Game consoles Mobile/cell phones PDAs Interactive TV set-top boxes Search engines and other indexing programs And many moreThis large variety of user agents, of different t
32、echnical finesse (and old user agents that dont get updated), is also a great danger for JavaScript.Not all visitors to your web site will experience the JavaScript enhancements you applied to it. A lot of them will also have JavaScript turned offfor security reasons. JavaScript can be used for good and for evil. If the operating systemlike unpatched Windowsallows you to, you can install viruses or Trojan Horses on a computer via JavaScript or read out user information and send it to another server.Note There is no way of knowing what t
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 環(huán)保工程招標(biāo)文件編制及評審培訓(xùn)
- 2025年中藥配方顆粒質(zhì)量標(biāo)準(zhǔn)提升與市場拓展策略分析
- 黔南民族醫(yī)學(xué)高等??茖W(xué)?!端幚韺W(xué)實(shí)驗(yàn)B》2023-2024學(xué)年第一學(xué)期期末試卷
- 遼寧裝備制造職業(yè)技術(shù)學(xué)院《大學(xué)外語》2023-2024學(xué)年第一學(xué)期期末試卷
- 貴州經(jīng)貿(mào)職業(yè)技術(shù)學(xué)院《心理學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 撫州幼兒師范高等??茖W(xué)?!段湫g(shù)I》2023-2024學(xué)年第一學(xué)期期末試卷
- 唐山海運(yùn)職業(yè)學(xué)院《園林植物栽培學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025年制造業(yè)供應(yīng)鏈數(shù)字化協(xié)同與產(chǎn)業(yè)互聯(lián)網(wǎng)融合研究報(bào)告
- 物聯(lián)網(wǎng)安全事件響應(yīng)策略與智能修復(fù)系統(tǒng)-洞察及研究
- 小公司周年策劃方案
- 信息檢索智慧樹知到答案章節(jié)測試2023年齊魯工業(yè)大學(xué)
- 鋁鎂錳金屬屋面專項(xiàng)施工組織設(shè)計(jì)
- 攪拌器的型式
- 傳感器原理 磁電式傳感器
- XX印務(wù)有限公司采購控制程序
- 2.溝槽開挖(檢驗(yàn)批)質(zhì)量驗(yàn)收記錄表
- GB/T 18451.1-2022風(fēng)力發(fā)電機(jī)組設(shè)計(jì)要求
- GB/T 8433-1998紡織品色牢度試驗(yàn)?zāi)吐然味?游泳池水)
- GB/T 12719-2021礦區(qū)水文地質(zhì)工程地質(zhì)勘查規(guī)范
- 完整版隧道項(xiàng)目消防工程施工組織設(shè)計(jì)方案
- 幼兒教師如何應(yīng)對幼兒入園焦慮詳解
評論
0/150
提交評論