⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07_01.htm

📁 用perl编写CGI的好书。本书从解释CGI和底层HTTP协议如何工作开始
💻 HTM
字号:
<?label 7. JavaScript?><html><head><title>JavaScript (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch06_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch07_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h1 class="chapter">Chapter 7. JavaScript</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch07_01.htm">Background</a><br><a href="ch07_02.htm">Forms</a><br><a href="ch07_03.htm">Data Exchange</a><br><a href="ch07_04.htm">Bookmarklets</a><br></p></div><p>Looking <a name="INDEX-1515" />atthe title of this chapter, you probably said to yourself,"JavaScript? What does that have to do with CGI programming orPerl?" It's true that JavaScript is not Perl, and itcannot be used to write CGI scripts.<a href="#FOOTNOTE-9">[9]</a> However, in order to develop powerful web applications weneed to learn much more than CGI itself. Therefore, our discussionhas already covered HTTP and HTML forms and will later cover emailand SQL. JavaScript is yet another tool that, although notfundamental to creating CGI scripts, can help us create better<a name="INDEX-1516" />web applications.</p><blockquote><a name="FOOTNOTE-9" /><p>[9]Some web serversdo support server-side JavaScript, but not via CGI.</p></blockquote><p>In this chapter, we will focus on three specific applications ofJavaScript: validating user input in forms; generating semiautonomousclients; and bookmarklets. As we will soon see, all three of theseexamples use JavaScript on the client side but still rely on CGIscripts on the server side.</p><p>This chapter is not intended to be an introduction to JavaScript.Since many web developers learn HTML and JavaScript before turning toPerl and CGI, we will assume you've had some exposure toJavaScript already. If you haven't, or if you are interested inlearning more, you may wish to refer to <em class="citetitle">JavaScript: TheDefinitive Guide</em> by David Flanagan (O'Reilly &amp;Associates, Inc.).</p><div class="sect1"><a name="ch07-52111" /><h2 class="sect1">7.1. Background</h2><p>Before we get started, let's discuss the background ofJavaScript. As we said, we'll skip the introduction toJavaScript programming, but we should clear up possible confusionsabout what we mean when we refer to JavaScript and how JavaScriptrelates to similar technologies.</p><a name="ch07-1-fm2xml" /><div class="sect2"><h3 class="sect2">7.1.1. History</h3><p>JavaScript was originally developed for<a name="INDEX-1517" />Netscape Navigator2.0. JavaScript has very little to do with Java despite thesimilarity in names. The languages were developed independently, andJavaScript was originally called <em class="firstterm">LiveScript</em>.However Sun Microsystems (the creator of Java) and Netscape struck adeal, and LiveScript was renamed to JavaScript shortly before itsrelease. Unfortunately, this single marketing decision has confusedmany who believe that Java and JavaScript are more similar than theyare.</p><p>Microsoft later created their own JavaScript implementation forInternet Explorer 3.0, which they called<em class="firstterm">JScript</em><a name="INDEX-1518" /><a name="INDEX-1519" /><a name="INDEX-1520" />. Initially, JScript was mostlycompatible with JavaScript, but then Netscape and Microsoft developedtheir languages in different directions. The dynamic behaviorprovided in the latest versions of these languages is now verydifferent.</p><p>Fortunately, there have been efforts to standardize these languagesvia <a name="INDEX-1521" />ECMAScript and DOM.<em class="firstterm">ECMAScript</em> is an ECMA standard that definesthe syntax and structure of the language that JScript and JavaScriptwill become. ECMAScript itself is not specific to the Web and is notdirectly useful as a language because it doesn't do anything;it only defines a few very basic objects. That's where the<em class="firstterm">Document ObjectModel</em><a name="INDEX-1522" /> (DOM) comes in. The DOM is a separatestandard being developed by the World Wide Web Consortium to definethe <a name="INDEX-1523" /><a name="INDEX-1524" /> <a name="INDEX-1,525" />objects used with HTML and XMLdocuments without respect to a particular programming language.</p><p>The end result of these efforts is that JavaScript and JScript shouldone day adopt both the ECMAScript standard as well as the DOMstandard. They will then share a uniform structure and a common modelfor interacting with documents. At this point they will both becomecompatible and we can write client-side scripting code that will workacross all browsers that support this standard.</p><p>Despite the distinction between JavaScript and JScript, most peopleuse the term JavaScript in reference to any implementation ofJavaScript or JScript, regardless of browser; we will also use theterm JavaScript in this manner.</p></div><a name="ch07-2-fm2xml" /><div class="sect2"><h3 class="sect2">7.1.2. Compatibility</h3><p>The biggest issue with<a name="INDEX-1526" /><a name="INDEX-1527" />JavaScript is the problem we justdiscussed: browser compatibility. This is not something we typicallyneed to worry about with CGI scripts, which execute on the webserver. JavaScript executes in the user's browser, so in orderfor our code to execute, the browser needs to support JavaScript,JavaScript needs to be enabled (some users turn it off), and theparticular implementation of JavaScript in the browser needs to becompatible with our code.</p><p>You must decide for yourself whether the benefits that you gain fromusing JavaScript outweigh these requirements that it places upon theuser. Many sites compromise by using JavaScript to provide enhancedfunctionality to those users who have it, but without restrictingaccess to those users who do not. Most of our examples in thischapter will follow this model. We will also avoid newer languagefeatures and confine ourselves to JavaScript 1.1, which is largelycompatible between the different browsers that support JavaScript.</p></div></div><hr align="left" width="515" /><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch06_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td width="172" valign="top" align="right"><a href="ch07_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td width="172" valign="top" align="left">6.5. Mason</td><td width="171" valign="top" align="center"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td width="172" valign="top" align="right">7.2. Forms</td></tr></table></div><hr align="left" width="515" /><img src="../gifs/navbar.gif" alt="Library Navigation Links" usemap="#library-map" border="0" /><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area href="../index.htm" coords="1,1,83,102" shape="rect" /><area href="../lnut/index.htm" coords="81,0,152,95" shape="rect" /><area href="../run/index.htm" coords="172,2,252,105" shape="rect" /><area href="../apache/index.htm" coords="238,2,334,95" shape="rect" /><area href="../sql/index.htm" coords="336,0,412,104" shape="rect" /><area href="../dbi/index.htm" coords="415,0,507,101" shape="rect" /><area href="../cgi/index.htm" coords="511,0,601,99" shape="rect" /></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -