professional javascript for web developers 2nd_edition读书笔记(二)

<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:Palatino-Roman; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:Palatino-Italic; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:FranklinGothic-Heavy; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:Arial; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:WileyCode-Regular; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:方正舒体; mso-font-charset:134; mso-generic-font-family:auto; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@WileyCode-Regular"; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:134; mso-generic-font-family:auto; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:1 135135232 16 0 262144 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1013972; mso-list-type:hybrid; mso-list-template-ids:1137321760 67698697 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:62.9pt; text-indent:-21.0pt; font-family:Wingdings;} @list l1 {mso-list-id:604197669; mso-list-type:hybrid; mso-list-template-ids:-422024922 67698691 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l1:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt; font-family:Wingdings;} @list l2 {mso-list-id:1910143673; mso-list-type:hybrid; mso-list-template-ids:-629619600 67698699 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l2:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:41.95pt; text-indent:-21.0pt; font-family:Wingdings;} @list l3 {mso-list-id:2102949137; mso-list-type:hybrid; mso-list-template-ids:1963077518 620125154 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l3:level1 {mso-level-text:%1、; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:39.0pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

第二章 JavaScript in HTML

1 The < script > Element

< script > html 的正式规范的范围。 HTML 4.01 < script > 定义如下特性:

n   charset - 可选,用 src 制定字符集编码。很少用,因大部分浏览器不太支持。

n   defer - 可选, script 的执行将会安全延期到 document 的内容完全解析现实之后再执行。

n   language   - 不赞成,大多数浏览器将忽略此特性,所以不应使用此特性。

n   src   - 可选,外部 script 的文件。

n   type - 必须。 看做 language 的替代。指出脚本语言的 the content type (也称为 MIME type ),一般此值为 text/javascript ”。

包含 < script > 的两种方式:

1 、在网页中包含在线 < script > 只需设置 type 即可,如

< script type=”text/javascript”>

function sayHi()

{

alert( Hi! );

}

< /script >

          < script > element 中的代码会自上往下顺序解释,只有此代码执行后,后面的页面才会显示。

            2 、在网页中包含外部文件, 则设置 src 如: < script type= text/javascript src= example.js > < /script >

NOTE: <script> 元素如果包含有利用 src 包含外部文件,则 < script > < /script > tags 中间不能再有 JavaScript 代码。、

2 Tag Placement

         通常, < script > 放在 <head> 中,这样做的目的是将 JavaScript 外部文件和 css 外部文件放在同一个区域中,但这样的缺点是:只有全部的外部 JavaScript 文件完全下载完、解析完、解释完后,页面才开始呈现(浏览器只有收到 <body> 标签时才开始呈现页面内容)。

3 Deferred Scripts

         HTML 4.01 < script > 元素定义了一个属性 defer ,如果设定 defer= defer ”,则只有在整个页面执行完后,此 < script > 才开始运行。此属性相当于 < script > 放在整个网页的底部。 IE and Firefox 3.1 支持此属性,其它的浏览器未必支持(注意),此属性例子如:

< html >

< head >

< title > Example HTML Page < /title >

< script type= text/javascriptdefer=defer src=example1.js > < /script >

< /head >

< body >

< !-- content here -- >

< /body >

< /html >

在上例中,只有当浏览器收到标签 < /html > 后才会执行 <script> 中代码;

4 Changes in XHTML

       Extensible HyperText Markup Language, or XHTML , is a reformulation of HTML as an application

of XML. XHTML 的编码规则比 html 的编码规则要严格的多,同样影响到在线 < script/ >

         HTML 中, < script > 元素有其特别的规则来管理其内容如何被解析,此与 XHTML 中不同,如: 在语句 a < b 中小于号( < )被解释为标签的开始。

         有两种方法来解决 XHTML 语法错误:

1、   利用实体 entity ( & lt; ) 代替小于号( < : 此方法不易读。

< script type= text/javascript >

function compare(a, b)

{

if (a &lt; b)

  {

alert( A is less than B );

} else if (a > b)

{

alert(}A is greater than B );

} else

{

alert( A is equal to B );

}

}

< /script >

2、   CData 段包围 script

< script type= text/javascript >

  < ![CDATA[

function compare(a, b)

{

if (a < b)

{

alert( A is less than B );

} else if (a > b)

  {

alert( A is greater than B );

} else

{

alert( A is equal to B );

}

}

]] >

  < /script >

但有些浏览器不支持 < ![CDATA[    ]] > ,则此 < ![CDATA[    ]] > 必须掉注释。

                 < script type= text/javascript >

// < ![CDATA[

                             script 内容。。。。。。。

//]] >

  < /script >

5 Deprecated Syntax

         有些浏览器不支持 JavaScript ( 如: Mosaic) ,不支持的浏览器将会在页面上直接输出 < script > 的内容。这将破坏原来页面的整体。

         解决方案:用 HTML 注释将 script 代码封装起来。不支持 JavaScript 的浏览器将会忽略掉封装的内容,支持 JavaScript 的浏览器将会正常解析。

         < script > < !--

function sayHi()

{

alert( Hi! );

}

//-- > < /script >

6 Inline Code versus External Files

         利用 External Files 的优势:

ü   Maintainability (易于维护)-  开发者可以只编辑 External File ,独立于利用此文件的标签。

ü   Caching (缓存)   —  通过某特定设定,浏览器可缓存 External File ,如:如果两个页面引用同一个 External File ,则此文件只加载一次。

ü   Future - proof   —   引用 External File ,不存在前述担心的语法问题。 HTML and XHTML 包含 External File 的语法是一样的。

7 Document Modes

       DOCTYPE document type( 文档类型 ) 的简写,在W eb 设计中用来说明你用的 XHTML 或者 HTML 是什么版本。   要建立符合标准的网页, DOCTYPE 声明是必不可少的关键组成部分;除非你的 XHTML 确定了一个正确的 DOCTYPE ,否则你的标识和 CSS 都不会生效。   设计网页的过程中,应该怎样正确的选择和使用 DOCTYPE

        

8 The < noscript > Element

         老的浏览器不支持 JavaScript < noscript > 将在不支持 JavaScript 的浏览器中作为 <script> 替代。只有遇到如下两种情况, < noscript > 中的内容将会显示:

Ø  浏览器不支持 scripting

Ø  浏览器的 scripting 支持被关闭

例如:

< body >

< noscript >

< p > This page requires a JavaScript-enabled browser. < /p >

< /noscript >

< /body >

         如果遇到以上两种情况:则显示 This page requires a JavaScript-enabled browser. 否则 不会显示。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值