<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.crossyou.cn/styles/feedsky0.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.crossyou.cn" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/crossyou2009" type="application/rss+xml"></fs:self_link><lastBuildDate>Mon, 14 May 2012 15:37:28 GMT</lastBuildDate><title>CrossYou'Blog</title><description>弱水三千，只取一瓢</description><image><url>http://www.feedsky.com/images/feedsky_logologo.gif</url><title>CrossYou'Blog</title><link>http://www.crossyou.cn</link></image><link>http://www.crossyou.cn</link><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>1</sy:updateFrequency><language>en</language><pubDate>Mon, 14 May 2012 15:37:28 GMT</pubDate><item><title>Google的html/css规范指南</title><link>http://www.crossyou.cn/googles-html-css-specification-guide.htm</link><content:encoded>&lt;h3&gt;常规样式规则&lt;/h3&gt;
&lt;h4&gt;协议&lt;/h4&gt;
&lt;p&gt;引入的assets资源文件（js、css、图片文件）&lt;strong&gt;忽略协议&lt;/strong&gt;（&lt;strong&gt;http:, https:&lt;/strong&gt;），比如：&lt;br /&gt;
&lt;span id=&quot;more-412&quot;&gt;&lt;/span&gt;&lt;br /&gt;
不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;script src=&quot;http://www.google.com/js/gweb/analytics/autotrack.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;script src=&quot;//www.google.com/js/gweb/analytics/autotrack.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.example {
  background: url(http://www.google.com/images/example);
}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.example {
  background: url(//www.google.com/images/example);
}&lt;/pre&gt;
&lt;p&gt;关于google的这点建议，有兴趣的朋友看&lt;a href=&quot;http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just&quot; target=&quot;_blank&quot;&gt;http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just&lt;/a&gt;，里面有详细的讨论，根据一位网友的测试，相对url在IE7、IE8下存在二次加载的问题。&lt;/p&gt;
&lt;h3&gt;常规格式规则&lt;/h3&gt;
&lt;h4&gt;缩进&lt;/h4&gt;
&lt;p&gt;使用二个空格缩进&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;ul&amp;gt;
  &amp;lt;li&amp;gt;Fantastic&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;Great&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.example {
  color: blue;
}&lt;/pre&gt;
&lt;h4&gt;大写&lt;/h4&gt;
&lt;p&gt;只使用小写。&lt;/p&gt;
&lt;p&gt;所有的代码只使用小写字母（PS:淘宝的做法是如果跟js的DOM操作相关，作为钩子使用J_Trigger类似的方式）：包括元素名称、样式名、属性名（除了text/CDATA）。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;A HREF=&quot;/&quot;&amp;gt;Home&amp;lt;/A&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;img src=&quot;google.png&quot; alt=&quot;Google&quot; /&amp;gt;&lt;/pre&gt;
&lt;h4&gt;尾部空白&lt;/h4&gt;
&lt;p&gt;删掉冗余的行尾空格。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;What?_&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;Yes please.&lt;/pre&gt;
&lt;h3&gt;常规Meta规则&lt;/h3&gt;
&lt;h4&gt;编码&lt;/h4&gt;
&lt;p&gt;使用&lt;strong&gt;utf-8&lt;/strong&gt;编码。&lt;/p&gt;
&lt;p&gt;指定页面的文档编码为utf-8&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;meta charset=&quot;utf-8&quot;&amp;gt;&lt;/pre&gt;
&lt;p&gt;不需要特别指定样式引用的编码为utf-8。&lt;/p&gt;
&lt;p&gt;（ps：关于html编码指定方面的内容，可以看&lt;a href=&quot;http://www.w3.org/International/tutorials/tutorial-char-enc/en/all.html&quot; target=&quot;_blank&quot;&gt;《 Character Sets &amp;amp; Encodings in XHTML, HTML and CSS》&lt;/a&gt;）&lt;/p&gt;
&lt;h4&gt;注释&lt;/h4&gt;
&lt;p&gt;如果可能，注释还是必不可少的。&lt;/p&gt;
&lt;p&gt;使用注释说明下代码：它包括了什么，它的目的是什么，为什么优先使用它。&lt;/p&gt;
&lt;h4&gt;行动项目&lt;/h4&gt;
&lt;p&gt;Google建议养成写TODO的习惯，特别是在项目中，记录下一些要改，但来不及修改的地方，或指派其他同事做修改。&lt;/p&gt;
&lt;p&gt;高亮TODO，不同的编辑器有不一样的方式，比如idea是TODO:。&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;{# TODO(john.doe): revisit centering #}
&amp;lt;center&amp;gt;Test&amp;lt;/center&amp;gt;&lt;/pre&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!-- TODO: remove optional tags --&amp;gt;
&amp;lt;ul&amp;gt;
&amp;lt;li&amp;gt;Apples&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;Oranges&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;h3&gt;常规html设计规则&lt;/h3&gt;
&lt;h4&gt;文档类型&lt;/h4&gt;
&lt;p&gt;使用html5文档声明：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/pre&gt;
&lt;p&gt;不再使用XHTML（ application/xhtml+xml）。&lt;/p&gt;
&lt;h4&gt;HTML 的正确性&lt;/h4&gt;
&lt;p&gt;可以使用一些工具，检验你html的正确性，比如&lt;a href=&quot;http://validator.w3.org/&quot; target=&quot;_blank&quot;&gt; W3C HTML validator&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;
&lt;article&gt;This is only a test.&lt;/article&gt;
&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;meta charset=&quot;utf-8&quot;&amp;gt;
&amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
&amp;lt;article&amp;gt;This is only a test.&amp;lt;/article&amp;gt;&lt;/pre&gt;
&lt;h4&gt;HTML 的语义性&lt;/h4&gt;
&lt;p&gt;使用富含语义性的标签（ps:建议掌握html5新增的部分语义标签）。&lt;/p&gt;
&lt;p&gt;Google特别指出了要确保html的可用性，看下面的代码&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;div onclick=&quot;goToRecommendations();&quot;&amp;gt;All recommendations&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;a href=&quot;recommendations/&quot;&amp;gt;All recommendations&amp;lt;/a&amp;gt;&lt;/pre&gt;
&lt;h4&gt;多媒体元素降级处理&lt;/h4&gt;
&lt;p&gt;给多媒体元素，比如canvas、videos、 images增加alt属性，提高可用性（特别是常用的img标签，尽可量得加上alt属性，提供图片的描述信息）。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;img src=&quot;spreadsheet.png&quot;&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;img src=&quot;spreadsheet.png&quot; alt=&quot;Spreadsheet screenshot.&quot;&amp;gt;&lt;/pre&gt;
&lt;h4&gt;html、css、javascript三层分离&lt;/h4&gt;
&lt;p&gt;尽可能保持结构（html结构标签）、描述（css）、行为（javascript）的分离，并且让他们尽可能少的交互。确保html文档内容只有html的结构，将css和javascript以资源的方式引入。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;title&amp;gt;HTML sucks&amp;lt;/title&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;base.css&quot; media=&quot;screen&quot;&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;grid.css&quot; media=&quot;screen&quot;&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;print.css&quot; media=&quot;print&quot;&amp;gt;
&amp;lt;h1 style=&quot;font-size: 1em;&quot;&amp;gt;HTML sucks&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;I’ve read about this on a few sites but now I’m sure:
&amp;lt;u&amp;gt;HTML is stupid!!1&amp;lt;/u&amp;gt;
&amp;lt;center&amp;gt;I can’t believe there’s no way to control the styling of
my website without doing everything all over again!&amp;lt;/center&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;title&amp;gt;My first CSS-only redesign&amp;lt;/title&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;default.css&quot;&amp;gt;
&amp;lt;h1&amp;gt;My first CSS-only redesign&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;I’ve read about this on a few sites but today I’m actually
doing it: separating concerns and avoiding anything in the HTML of
my website that is presentational.
&amp;lt;p&amp;gt;It’s awesome!&lt;/pre&gt;
&lt;h4&gt;实体引用&lt;/h4&gt;
&lt;p&gt;在html页面中避免使用实体引用。&lt;/p&gt;
&lt;p&gt;如果你的文件是utf-8编码，就不需要使用像&lt;strong&gt; —&lt;/strong&gt;, &lt;strong&gt;”&lt;/strong&gt;, or &lt;strong&gt;☺&lt;/strong&gt;的实体引用。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;The currency symbol for the Euro is “&amp;amp;eur;”.&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;The currency symbol for the Euro is “€”.&lt;/pre&gt;
&lt;h4&gt;可选的标签&lt;/h4&gt;
&lt;p&gt;忽略一些可选的标签，比如&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;Spending money, spending bytes&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;p&amp;gt;Sic.&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;title&amp;gt;Saving money, saving bytes&amp;lt;/title&amp;gt;
&amp;lt;p&amp;gt;Qed.&lt;/pre&gt;
&lt;p&gt;html5的文档，可以忽略head、body标签。&lt;/p&gt;
&lt;p&gt;所有可忽略的标签，可以看&lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#syntax-tag-omission&quot; target=&quot;_blank&quot;&gt;《 HTML5 specification 》&lt;/a&gt;，&lt;/p&gt;
&lt;h4&gt;type属性&lt;/h4&gt;
&lt;p&gt;样式和脚本引用可以忽略type属性。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;//www.google.com/css/maia.css&quot; type=&quot;text/css&quot;&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;//www.google.com/css/maia.css&quot;&amp;gt;&lt;/pre&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;script src=&quot;//www.google.com/js/gweb/analytics/autotrack.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;script src=&quot;//www.google.com/js/gweb/analytics/autotrack.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;h3&gt;html格式规则&lt;/h3&gt;
&lt;h4&gt;常规格式&lt;/h4&gt;
&lt;p&gt;每一块、每一列表、每一表格元素都需要另起一行，并缩进每个子元素。&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;blockquote&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;em&amp;gt;Space&amp;lt;/em&amp;gt;, the final frontier.&amp;lt;/p&amp;gt;
&amp;lt;/blockquote&amp;gt;&lt;/pre&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;ul&amp;gt;
&amp;lt;li&amp;gt;Moe
&amp;lt;li&amp;gt;Larry
&amp;lt;li&amp;gt;Curly
&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;table&amp;gt;
&amp;lt;thead&amp;gt;
&amp;lt;tr&amp;gt;
&amp;lt;th scope=&quot;col&quot;&amp;gt;Income&amp;lt;/th&amp;gt;
&amp;lt;th scope=&quot;col&quot;&amp;gt;Taxes&amp;lt;/th&amp;gt;
&amp;lt;tbody&amp;gt;
&amp;lt;tr&amp;gt;
&amp;lt;td&amp;gt;$ 5.00&amp;lt;/td&amp;gt;
&amp;lt;td&amp;gt;$ 4.50&amp;lt;/td&amp;gt;
&amp;lt;/table&amp;gt;&lt;/pre&gt;
&lt;h3&gt;css样式规则&lt;/h3&gt;
&lt;h4&gt;css验证&lt;/h4&gt;
&lt;p&gt;尽可能验证css的合法性，可以使用 &lt;a href=&quot;http://jigsaw.w3.org/css-validator/&quot; target=&quot;_blank&quot;&gt;W3C CSS validator&lt;/a&gt;。&lt;/p&gt;
&lt;h5&gt;id和class名&lt;/h5&gt;
&lt;p&gt;使用富有含义和通用的id和class名。 使用功能性和通用性的命名方式减少文档或模板的不必要的改动。 不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;/* Not recommended: meaningless */
#yee-1901 {}

/* Not recommended: presentational */
.button-green {}
.clear {}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;/* Recommended: specific */
#gallery {}
#login {}
.video {}

/* Recommended: generic */
.aux {}
.alt {}&lt;/pre&gt;
&lt;h4&gt;id和class的命名风格&lt;/h4&gt;
&lt;p&gt;id和class的命名在保持语义性的同时尽可能的短。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;#navigation {}
.atr {}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;#nav {}
.author {}&lt;/pre&gt;
&lt;p&gt;可以缩写单词，但缩写后务必能让人明白其含义。比如author缩写成atr就非常费解。&lt;/p&gt;
&lt;h4&gt;选择器&lt;/h4&gt;
&lt;p&gt;避免出现多余的祖先选择器。（存在性能上的差异问题，可以看&lt;a href=&quot;http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/&quot; target=&quot;_blank&quot;&gt; performance reasons&lt;/a&gt;）&lt;/p&gt;
&lt;p&gt;避免出现元素标签名作为选择器的一部分。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;ul#example {}
div.error {}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;#example {}
.error {}&lt;/pre&gt;
&lt;h4&gt;简化css属性写法&lt;/h4&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;border-top-style: none;
font-family: palatino, georgia, serif;
font-size: 100%;
line-height: 1.6;
padding-bottom: 2em;
padding-left: 1em;
padding-right: 1em;
padding-top: 0;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;border-top: 0;
font: 100%/1.6 palatino, georgia, serif;
padding: 0 1em 2em;&lt;/pre&gt;
&lt;p&gt;使用简洁的属性写法有利于提高可读性和解析效率。&lt;/p&gt;
&lt;h4&gt;0和单位&lt;/h4&gt;
&lt;p&gt;属性值为0时，忽略单位。&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;margin: 0;
padding: 0;&lt;/pre&gt;
&lt;h4&gt;属性值出现小数点忽略0&lt;/h4&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;font-size: .8em;&lt;/pre&gt;
&lt;h4&gt;url的引用&lt;/h4&gt;
&lt;p&gt;使用url()时忽略刮号中的””。&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;@import url(//www.google.com/css/go.css);&lt;/pre&gt;
&lt;h5&gt;16进制符号&lt;/h5&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;color: #eebbcc;&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;color: #ebc;&lt;/pre&gt;
&lt;h4&gt;前缀&lt;/h4&gt;
&lt;p&gt;给选择器样式名增加前缀（可选）。&lt;/p&gt;
&lt;p&gt;在大的项目（多人协作）中使用前缀可以减少样式冲突，同时可以明确选择器归属含义。&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.adw-help {} /* AdWords */
#maia-note {} /* Maia */&lt;/pre&gt;
&lt;h4&gt;id和class名的分隔符&lt;/h4&gt;
&lt;p&gt;单词使用“-”来连接。&lt;/p&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;/* Not recommended: does not separate the words “demo” and “image” */
.demoimage {}

/* Not recommended: uses underscore instead of hyphen */
.error_status {}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;#video-id {}
.ads-sample {}&lt;/pre&gt;
&lt;h4&gt;Hacks&lt;/h4&gt;
&lt;p&gt;尽可能地避免使用hack的方式解决浏览器样式兼容性问题。&lt;/p&gt;
&lt;p&gt;尽量避免使用CSS filters。&lt;/p&gt;
&lt;h3&gt;css格式规则&lt;/h3&gt;
&lt;h4&gt;css属性按字母顺序书写&lt;/h4&gt;
&lt;p&gt;（PS：排序忽略浏览器前缀，比如-moz-，-webkit-）&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;background: fuchsia;
border: 1px solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
color: black;
text-align: center;
text-indent: 2em;&lt;/pre&gt;
&lt;h4&gt;块内容缩进&lt;/h4&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;@media screen, projection {

  html {
    background: #fff;
    color: #444;
  }

}&lt;/pre&gt;
&lt;p&gt;缩进所有的&lt;a href=&quot;http://www.w3.org/TR/CSS21/syndata.html#block&quot; target=&quot;_blank&quot;&gt;块状内容&lt;/a&gt;。&lt;/p&gt;
&lt;h4&gt;不可缺少的;&lt;/h4&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.test {
  display: block;
  height: 100px
}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;.test {
  display: block;
  height: 100px;
}&lt;/pre&gt;
&lt;h4&gt;属性值前增加个空格&lt;/h4&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;h3 {
  font-weight:bold;
}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;h3 {
  font-weight: bold;
}&lt;/pre&gt;
&lt;h4&gt;分隔选择器&lt;/h4&gt;
&lt;p&gt;不推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;a:focus, a:active {
  position: relative; top: 1px;
}&lt;/pre&gt;
&lt;p&gt;推荐的写法：&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;h1,
h2,
h3 {
  font-weight: normal;
  line-height: 1.2;
}&lt;/pre&gt;
&lt;h4&gt;1行只有一个css属性，二个规则间有一个空行&lt;/h4&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;html {
  background: #fff;
}

body {
  margin: auto;
  width: 50%;
}&lt;/pre&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/css-hack-finishing-summary.htm&quot; title=&quot;CSS Hack 整理总结&quot;&gt;CSS Hack 整理总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-kvo-google-map-api.htm&quot; title=&quot;Javascript中的KVO实现 &amp;#8211; Google Map API 示例&quot;&gt;Javascript中的KVO实现 &amp;#8211; Google Map API 示例&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/google-logo-pac-man-30-anniversary.htm&quot; title=&quot;谷歌logo-吃豆人(Pac-Man)30周年纪念&quot;&gt;谷歌logo-吃豆人(Pac-Man)30周年纪念&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/reset-css.htm&quot; title=&quot;重新设置CSS(reset.css)&quot;&gt;重新设置CSS(reset.css)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373418/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/googles-html-css-specification-guide.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/googles-html-css-specification-guide.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>常规样式规则 协议 引入的assets资源文件（js、css、图片文件）忽略协议（http:, https:），比如： 不推荐的写法： &amp;#60;script src=&quot;http://www.google.com/js/gweb/analytics/autotrack.js&quot;&amp;#62;&amp;#60;/script&amp;#62; 推荐的写法： &amp;#60;script src=&quot;//www.google.com/js/gweb/analytics/autotrack.js&quot;&amp;#62;&amp;#60;/script&amp;#62; 不推荐的写法： .example { background: url(http://www.google.com/images/example); } 推荐的写法： .example { background: url(//www.google.com/images/example); } 关于google的这点建议，有兴趣的朋友看http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just，里面有详细的讨论，根据一位网友的测试，相对url在IE7、IE8下存在二次加载的问题。 常规格式规则 缩进 使用二个空格缩进 &amp;#60;ul&amp;#62; &amp;#60;li&amp;#62;Fantastic&amp;#60;/li&amp;#62; &amp;#60;li&amp;#62;Great&amp;#60;/li&amp;#62; &amp;#60;/ul&amp;#62; .example { color: blue; } 大写 只使用小写。 所有的代码只使用小写字母（PS:淘宝的做法是如果跟js的DOM操作相关，作为钩子使用J_Trigger类似的方式）：包括元素名称、样式名、属性名（除了text/CDATA）。 不推荐的写法： &amp;#60;A HREF=&quot;/&quot;&amp;#62;Home&amp;#60;/A&amp;#62; 推荐的写法： &amp;#60;img src=&quot;google.png&quot; alt=&quot;Google&quot; /&amp;#62; 尾部空白 删掉冗余的行尾空格。 不推荐的写法： What?_ 推荐的写法： Yes please. 常规Meta规则 编码 [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373418/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/googles-html-css-specification-guide.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>Web前端</category><category>html</category><category>规范</category><category>css</category><category>google</category><pubDate>Mon, 14 May 2012 23:37:28 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/googles-html-css-specification-guide.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=412</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/googles-html-css-specification-guide.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373418/6050201</fs:itemid></item><item><title>PHP：将图片编码成base64</title><link>http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm</link><content:encoded>&lt;p&gt;Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一，事实上，可以base64编码的文件不仅仅是图片，其他可以通过Http传输的数据文件也可以base64编码，恩，差不多，就这样.&lt;/p&gt;
&lt;p&gt;想了解更多情况的童鞋可以看看这篇文章《&lt;a href=&quot;http://www.zhangxinxu.com/wordpress/2012/04/base64-url-image-%E5%9B%BE%E7%89%87-%E9%A1%B5%E9%9D%A2%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;小tip: base64:URL背景图片与web页面性能优化&lt;/a&gt;》。&lt;/p&gt;
&lt;p&gt;今天主要分享一段用PHP实现 将本地图片编码成base64 的代码：&lt;br /&gt;
&lt;span id=&quot;more-411&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;/**
 * 将给定的本地图片编码为base64
 *
 * @param {String} $file 所要编码的本地文件地址
 */
function imgBase64($file){
	$fo = fopen($file, 'r');
	if(!$fo){
		die('open file fail!');
	}
	$imgInfo = getimagesize($file);

	//对图片进行base64编码
	$base64 = chunk_split(base64_encode(fread($fo,filesize($file))));

	//判读图片类型
	switch($imgInfo[2]){
		case 1:
			$type = 'gif';
			break;
		case 2:
			$type = 'jpg';
			break;
		case 3:
			$type = 'png';
			break;
	}
	fclose($fo);

	return 'data:image/'.$type.';base64,'.$base64;
}&lt;/pre&gt;
&lt;p&gt;可以到这里看看：图片base64编码:&lt;a href=&quot;http://static.crossyou.cn/study/image-base64-tester.php&quot;&gt;示例页面&lt;/a&gt;&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/php-powerful-functions-that-are-less.htm&quot; title=&quot;PHP中功能强大却少使用的函数&quot;&gt;PHP中功能强大却少使用的函数&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/%e6%94%b6%e8%97%8f%e5%87%a0%e4%b8%aaphp%e5%8a%a9%e6%89%8b%e5%87%bd%e6%95%b0.htm&quot; title=&quot;收藏几个PHP助手函数&quot;&gt;收藏几个PHP助手函数&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/just-a-cometdemo-app-power.htm&quot; title=&quot;『演示』Just a CometDemo App Powered by CrossYou&quot;&gt;『演示』Just a CometDemo App Powered by CrossYou&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/compressor.htm&quot; title=&quot;Phpcompressor-1.0.5 for linux  base on Yuicompressor&quot;&gt;Phpcompressor-1.0.5 for linux  base on Yuicompressor&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373419/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一，事实上，可以base64编码的文件不仅仅是图片，其他可以通过Http传输的数据文件也可以base64编码，恩，差不多，就这样. 想了解更多情况的童鞋可以看看这篇文章《小tip: base64:URL背景图片与web页面性能优化》。 今天主要分享一段用PHP实现 将本地图片编码成base64 的代码： /** * 将给定的本地图片编码为base64 * * @param {String} $file 所要编码的本地文件地址 */ function imgBase64($file){ $fo = fopen($file, 'r'); if(!$fo){ die('open file fail!'); } $imgInfo = getimagesize($file); //对图片进行base64编码 $base64 = chunk_split(base64_encode(fread($fo,filesize($file)))); //判读图片类型 switch($imgInfo[2]){ case 1: $type = 'gif'; break; case 2: $type = 'jpg'; break; case 3: $type = 'png'; break; } [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373419/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>base64</category><category>php</category><category>其它折腾</category><pubDate>Wed, 09 May 2012 11:34:56 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=411</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373419/6050201</fs:itemid></item><item><title>关于javascript数组去重的性能测试</title><link>http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm</link><content:encoded>&lt;p&gt;本文继上一篇文章《&lt;a title=&quot;Permanent Link to &amp;quot;Javascript数组去重 方法总结&amp;quot;&quot; href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; rel=&quot;bookmark&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;》所写，本文主要讲一下上篇文章所写的数组去重方法的性能问题，主要讨论一下那种方法性能最优。&lt;br /&gt;
&lt;span id=&quot;more-406&quot;&gt;&lt;/span&gt;&lt;br /&gt;
关于javascript的数组去重方法，某人刚才也提供了一种方法，经测试性能上有不少优势，特贴代码如下：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;// --- someone  renenglish---
function someone_uniq(a,strict){
	var o = {},
		arr = [],
		key;
	for(var i = 0; i &amp;lt; a.length; ++i){
		key = a[i];
		if(strict){
			if(typeof(a[i]) == 'number'){
				key = a[i]+'.number';
			}
			if(typeof(a[i]) == 'string'){
				key = a[i]+'.string';
			}
		}
		if(!o[key]){
			o[key] = true;
			arr.push(a[i]);
		}
	}
	return arr;
};&lt;/pre&gt;
&lt;p&gt;该方法，与怪飞的方法，性能上几乎不相上下，但经多次测试发现，及大数组的测试下也能看出该方法比之怪飞的方法还是稍微差了那么一点点，不过比我第一次写的要快30倍左右。 &lt;/p&gt;
&lt;p&gt;下面s是jQuery中的数组去重方法:jQuery.unique(),我做了一下简单的改写，以方便在此处直接使用，代码如下所示：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;//jQuery中的数组去重方法，不太适于测试，性能啊性能，难道真的这么差吗?
function jquery_unique(arg){
	var arg = arg.sort();
	for ( var i = 1, j = arg.length; i &amp;lt; j; i++ ) {
		if ( arg[i] === arg[ i - 1 ] ) {
			arg.splice( i--, 1 );
		}
	}
	return arg;
}&lt;/pre&gt;
&lt;p&gt;该方法的思路：&lt;br /&gt;
对数组排序，判断相邻的值是否相等&lt;br /&gt;
如果相等，则用splice()删除相等的元素&lt;br /&gt;
恩，不过该方法的性能实在不敢恭维，我在FF下处理一个长度1000的数组，浏览器就直接死掉，而之前写的方法，均可以处理长度100000的数组，这&amp;#8230;&lt;/p&gt;
&lt;p&gt;最后是&lt;a href=&quot;http://qwrap.com/&quot; rel=&quot;nofollow&quot;&gt;QWrap&lt;/a&gt;框架中的快速去重法，因代码有点长，不在此处贴代码了，可直接到测试页面中测试其性能。&lt;/p&gt;
&lt;p&gt;最后，附上一个比较直观的性能测试页面：&lt;br /&gt;
&lt;a href=&quot;http://static.crossyou.cn/study/js-array-no-repeart-tester.html&quot;&gt;http://static.crossyou.cn/study/js-array-no-repeart-tester.html&lt;/a&gt;&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; title=&quot;Javascript数组去重 方法总结&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; title=&quot;Javascript原生全屏API&quot;&gt;Javascript原生全屏API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; title=&quot;mouseenter 和 mouseleave事件总结学习&quot;&gt;mouseenter 和 mouseleave事件总结学习&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-fifo-class.htm&quot; title=&quot;Javascript 先进先出队列类&quot;&gt;Javascript 先进先出队列类&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-recursion-function.htm&quot; title=&quot;Javascript 递归函数&quot;&gt;Javascript 递归函数&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373420/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm/feed</wfw:commentRss><slash:comments>2</slash:comments><description>本文继上一篇文章《Javascript数组去重 方法总结》所写，本文主要讲一下上篇文章所写的数组去重方法的性能问题，主要讨论一下那种方法性能最优。 关于javascript的数组去重方法，某人刚才也提供了一种方法，经测试性能上有不少优势，特贴代码如下： // --- someone renenglish--- function someone_uniq(a,strict){ var o = {}, arr = [], key; for(var i = 0; i &amp;#60; a.length; ++i){ key = a[i]; if(strict){ if(typeof(a[i]) == 'number'){ key = a[i]+'.number'; } if(typeof(a[i]) == 'string'){ key = a[i]+'.string'; } } if(!o[key]){ o[key] = true; arr.push(a[i]); } } return arr; }; 该方法，与怪飞的方法，性能上几乎不相上下，但经多次测试发现，及大数组的测试下也能看出该方法比之怪飞的方法还是稍微差了那么一点点，不过比我第一次写的要快30倍左右。 [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373420/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>数组去重</category><category>性能测试</category><category>Web前端</category><category>性能优化</category><category>javascript</category><pubDate>Sat, 28 Apr 2012 15:43:41 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=406</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373420/6050201</fs:itemid></item><item><title>Javascript数组去重 方法总结</title><link>http://www.crossyou.cn/javascript-no-repeat-method.htm</link><content:encoded>&lt;p&gt;如果什么都不去参考，只给我一个编辑器的话，让我实现去除javascript数组中重复元素的方法的话，我会这么写：&lt;br /&gt;
&lt;span id=&quot;more-405&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;var test_array = [1, 1, 2, 2, 3, 'a', 'a', '2', '3'];

/**
 * javascript数组去重方法
 * @param  {Array} arg [所要去重的数组]
 * @return {Array}     [去重后新的数组]
 */
function no_repeat_1(arg){
	var _arg = [];
	var _len = arg.length;
	for(var i = 0; i &amp;lt; _len; i++){
		if(in_array(arg[i], _arg, true)){
			continue;
		}
		_arg.push(arg[i]);
	}
	return _arg;
}

/**
 * 检查数组中是否存在某个值
 *
 * @param  {Mixed} needle [给定的某个元素]
 * @param  {Array} haystack [所要查找的数组]
 * @param  {Boolean} strict [如果为true 则会检查 needle 的类型是否和 haystack 中的相同]
 * @return {Boolean} [在 haystack 中搜索 needle ，如果找到则返回 TRUE，否则返回 FALSE]
 */
function in_array(needle, haystack, strict){
	if(typeof needle == undefined || typeof haystack == undefined){
		return false;
	}
	var len = haystack.length;
	for(var i = 0; i &amp;lt; len; i++){
		if(strict){
			if(needle === haystack[i]){
				return true;
			}
		} else {
			if(needle == haystack[i]){
				return true;
			}
		}
	}
	return false;
}

console.log(no_repeat_1(test_array));&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;我思路主要是这样的：&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;首先遍历这个要去重的数组，然后用in_array()方法判断，当前元素是否已经存在于当前的临时数组_arg中，如果存在，则continue跳过，否则，push当前的这个元素到_arg这个数组中，遍历完成之后，返回这个临时数组_arg，即为去重后的数组。&lt;/p&gt;
&lt;p&gt;注：我写的这个in_array() 方法第三个参数如果为true ，则会检查元素的类型是否相同。&lt;/p&gt;
&lt;p&gt;恩，就是这样的，这是我首先想到的一个方法。&lt;/p&gt;
&lt;p&gt;不过，我想应该还要更好的方法，好吧，接下来，我就分析一下从网络中找的一些数组去重的方法。&lt;/p&gt;
&lt;p&gt;下面是YUI中的源码：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;var test_array = [1, 1, 2, 2, 3, 'a', 'a', '2', '3'];

var toObject = function(a) {
	var o = {};
	for (var i = 0, j=a.length; i &lt; j; i = i+1) {// 这里我调整了下, YUI源码中是i&amp;lt;a.length
		o[a[i]] = true;
	}
	return o;
};
var keys = function(o) {
	var a=[], i;
	for (i in o) {
		if (o.hasOwnProperty(i)) {// 这里, YUI源码中是lang.hasOwnProperty(o, i)
			a.push(i);
		}
	}
	return a;
};
var yui_uniq= function(a) {
	return keys(toObject(a));
};

console.log(yui_uniq(test_array));&lt;/pre&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;该方法的思路：&lt;/strong&gt;见&lt;a title=&quot;巧妙去除数组中的重复项&quot; href=&quot;http://www.mytcer.com/357&quot; target=&quot;_blank&quot;&gt;《巧妙去除数组中的重复项》&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;1. 先以目标数组的值为key生成一个对象. 这一步是最核心的: 因为在一个对象中, key是无法重复的, 这样就很巧妙的排除了重复值;&lt;/p&gt;
&lt;p&gt;2. 遍历生成的对象, 将这些key取出来放到一个数组中, OK, 到此就大功告成了!(简单吧, 只需两步就行)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;该方法的特点：&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1. 对于该方法, 不论数组有多少项, 都只会遍历两次, 在性能上的优势较明显(想想自己以前的做法: 对数组项进行逐个对比, 其性能之差, 可想而知).&lt;/p&gt;
&lt;p&gt;2. 经我的测试, 该方法只适用于数组项为字符串, 数字的一维数组(我觉得, 对多维数组进行排除重复项的操作, 实在是太杯具了!).&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;来看看 &lt;a title=&quot;删除数组中重复项（uniq）&quot; href=&quot;http://www.planabc.net/2009/12/26/array_uniq/&quot; target=&quot;_blank&quot;&gt;怪飞&lt;/a&gt;的写法：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;var test_array = [1, 1, 2, 2, 3, 'a', 'a', '2', '3'];

var planabc_uniq = function (arr) {
	var a = [],
		o = {},
		i,
		v,
		cv, // corrected value
		len = arr.length;

	if (len &lt; 2) {
		return arr;
	}

	for (i = 0; i &lt; len; i++) {
		v = arr[i];

		/* closurecache 提供的函数中使用的是  cv = v + 0;，
		 * 这样就无法辨别类似[1, 10, &quot;1&quot;, &quot;10&quot;]的数组，
		 * 因为运算后 =&gt; 1, 10, 10, 100，很明显，出现了重复的标示符。
		 * 加前面就难道没问题吗？
		 * 有的：数组中不能出现类似01 、001，以 0 开头的数字，
		 * 但适用性比原先更广。
		 */
		cv = 0 + v;

		if (!o[cv]) {
			a.push(v);
			o[cv] = true;
		}
	}
	return a;
}

console.log(planabc_uniq(test_array));&lt;/pre&gt;
&lt;p&gt;该方法的特点是：只用一次循环便完成了删除数组中重复项，性能远高于YUI的写法。&lt;/p&gt;
&lt;p&gt;恩，下面稍微的改进了一下第一种方法：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;var test_array = [1, 1, 2, 2, 3, 'a', 'a', '2', '3'];

if(!Array.prototype.indexOf) {
	Array.prototype.indexOf = function (obj, fromIndex) {
		if (fromIndex == null) {
			fromIndex = 0;
		} else if (fromIndex &lt; 0) {
			fromIndex = Math.max(0, this.length + fromIndex);
		}

		for (var i = fromIndex; i &lt; this.length; i++) {
			if (this[i] === obj)
				return i;
		}
		return -1;
	};
}

function no_repeat_2(arg){
	var _arg = [];
	for(var i = 0; i &lt; arg.length; i++){
		if(_arg.indexOf(arg[i]) != -1){
			continue;
		}
		_arg.push(arg[i]);
	}
	return _arg;
}

console.log(no_repeat_2(test_array));&lt;/pre&gt;
&lt;p&gt;简单分析上面的几种方法，我觉得我写的第一种方法，性能上没啥优势，只能说思路清晰，很易懂，具体性能那个好，明天我会写个测试页面专门测试一下他们的执行效率。&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; title=&quot;关于javascript数组去重的性能测试&quot;&gt;关于javascript数组去重的性能测试&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; title=&quot;Javascript原生全屏API&quot;&gt;Javascript原生全屏API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; title=&quot;mouseenter 和 mouseleave事件总结学习&quot;&gt;mouseenter 和 mouseleave事件总结学习&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-fifo-class.htm&quot; title=&quot;Javascript 先进先出队列类&quot;&gt;Javascript 先进先出队列类&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-recursion-function.htm&quot; title=&quot;Javascript 递归函数&quot;&gt;Javascript 递归函数&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373421/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/javascript-no-repeat-method.htm/feed</wfw:commentRss><slash:comments>1</slash:comments><description>如果什么都不去参考，只给我一个编辑器的话，让我实现去除javascript数组中重复元素的方法的话，我会这么写： var test_array = [1, 1, 2, 2, 3, 'a', 'a', '2', '3']; /** * javascript数组去重方法 * @param {Array} arg [所要去重的数组] * @return {Array} [去重后新的数组] */ function no_repeat_1(arg){ var _arg = []; var _len = arg.length; for(var i = 0; i &amp;#60; _len; i++){ if(in_array(arg[i], _arg, true)){ continue; } _arg.push(arg[i]); } return _arg; } /** [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373421/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>数组</category><category>去重</category><category>Web前端</category><category>YUI</category><category>javascript</category><pubDate>Sat, 28 Apr 2012 00:15:34 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/javascript-no-repeat-method.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=405</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/javascript-no-repeat-method.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373421/6050201</fs:itemid></item><item><title>CSS Hack 整理总结</title><link>http://www.crossyou.cn/css-hack-finishing-summary.htm</link><content:encoded>&lt;p&gt;有关CSS的Hack，网络中不胜枚举，写此文也算是一个学习笔记，虽平时用的不多，但真用的时候却还要去网络中搜寻，倒不如整理到自己的博客里来，方便自己查阅学习。&lt;/p&gt;
&lt;p&gt;各种浏览器不断更新升级换代，即使是同一浏览器，在不同版本下的CSS表现也不尽相同，我也将会在工作以及业余页面制作中遇到的此类hack问题持续更新到本文，分享给读者，同时也是自己一个不断学习的过程。&lt;br /&gt;
&lt;span id=&quot;more-399&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://static.crossyou.cn/wordpress/media/2012/04/未命名.jpg&quot;&gt;&lt;img class=&quot;alignleft size-full wp-image-400&quot; title=&quot;CSS Hack&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/未命名.jpg&quot; alt=&quot;&quot; width=&quot;607&quot; height=&quot;228&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://static.crossyou.cn/wordpress/media/2012/04/css-attr-hack1.jpg&quot;&gt;&lt;img src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/css-attr-hack1.jpg&quot; alt=&quot;&quot; title=&quot;css-attr-hack&quot; width=&quot;607&quot; height=&quot;324&quot; class=&quot;alignleft size-full wp-image-403&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;读者可以到我整理的《&lt;a title=&quot;主流浏览器CSS Hack大全&quot; href=&quot;http://static.crossyou.cn/study/browser-css-hack-tester.html&quot;&gt;主流浏览器CSS Hack大全&lt;/a&gt;》详情介绍页中测试查看学习。&lt;/p&gt;
&lt;p&gt;如需了解更多可以去阅读下面来自 幸福收藏夹 的一些文章：&lt;/p&gt;
&lt;p&gt;《&lt;a href=&quot;http://sofish.de/1400&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;打败 IE 的葵花宝典：CSS Bug Table&lt;/a&gt;》&lt;br /&gt;
《&lt;a href=&quot;http://sofish.de/1331&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;说说CSS Hack 和向后兼容&lt;/a&gt;》&lt;br /&gt;
《&lt;a href=&quot;http://sofish.de/1315&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;CSS Hack For All A-grade Browsers&lt;/a&gt;》&lt;br /&gt;
《&lt;a href=&quot;http://sofish.de/1064&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;CSS Hack: 区分 IE6 / IE7 /IE8 /Firefox&lt;/a&gt;》&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/googles-html-css-specification-guide.htm&quot; title=&quot;Google的html/css规范指南&quot;&gt;Google的html/css规范指南&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/reset-css.htm&quot; title=&quot;重新设置CSS(reset.css)&quot;&gt;重新设置CSS(reset.css)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373422/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/css-hack-finishing-summary.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/css-hack-finishing-summary.htm/feed</wfw:commentRss><slash:comments>1</slash:comments><description>有关CSS的Hack，网络中不胜枚举，写此文也算是一个学习笔记，虽平时用的不多，但真用的时候却还要去网络中搜寻，倒不如整理到自己的博客里来，方便自己查阅学习。 各种浏览器不断更新升级换代，即使是同一浏览器，在不同版本下的CSS表现也不尽相同，我也将会在工作以及业余页面制作中遇到的此类hack问题持续更新到本文，分享给读者，同时也是自己一个不断学习的过程。 读者可以到我整理的《主流浏览器CSS Hack大全》详情介绍页中测试查看学习。 如需了解更多可以去阅读下面来自 幸福收藏夹 的一些文章： 《打败 IE 的葵花宝典：CSS Bug Table》 《说说CSS Hack 和向后兼容》 《CSS Hack For All A-grade Browsers》 《CSS Hack: 区分 IE6 / IE7 /IE8 /Firefox》 相关文章Google的html/css规范指南重新设置CSS(reset.css)&lt;img src=&quot;http://www1.feedsky.com/t1/638373422/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/css-hack-finishing-summary.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>Web前端</category><category>IE6</category><category>Hack</category><category>IE</category><category>css</category><pubDate>Thu, 26 Apr 2012 10:58:11 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/css-hack-finishing-summary.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=399</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/css-hack-finishing-summary.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373422/6050201</fs:itemid></item><item><title>jquery-tinyLightbox-plugin简单讲解</title><link>http://www.crossyou.cn/jquery-tinylightbox-plugin.htm</link><content:encoded>&lt;p&gt;话说这是我目前博客中所使用的一个图片高亮弹出插件，只因功能单纯，代码短小，用着不错，写篇博文，简单总结一下。&lt;/p&gt;
&lt;p&gt;效果如下图：&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-395&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div id=&quot;attachment_396&quot; class=&quot;wp-caption alignleft&quot; style=&quot;width: 387px&quot;&gt;&lt;a href=&quot;http://static.crossyou.cn/wordpress/media/2012/04/zhangzetain.jpg&quot;&gt;&lt;img class=&quot;size-full wp-image-396&quot; title=&quot;tinyLightbox中文使用讲解演示&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/zhangzetain.jpg&quot; alt=&quot;tinyLightbox中文使用讲解演示&quot; width=&quot;377&quot; height=&quot;278&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;tinyLightbox中文使用讲解演示&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;该插件的作用具体作用就是：当鼠标单击上图的第一张图片时，页面将会变成如下效果：高亮显示你所单击的图片。&lt;/p&gt;
&lt;div id=&quot;attachment_397&quot; class=&quot;wp-caption alignleft&quot; style=&quot;width: 310px&quot;&gt;&lt;a href=&quot;http://static.crossyou.cn/wordpress/media/2012/04/zhangzetian.jpg&quot;&gt;&lt;img class=&quot;size-medium wp-image-397&quot; title=&quot;这是插件效果图&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/zhangzetian-300x279.jpg&quot; alt=&quot;这是插件效果图&quot; width=&quot;300&quot; height=&quot;279&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;这是插件效果图&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;有关该插件的使用详情，可到《&lt;a title=&quot;tinyLightbox中文使用讲解&quot; href=&quot;http://static.crossyou.cn/study/jquery-tinyLightbox-plugin.html&quot;&gt;tinyLightbox中文使用讲解&lt;/a&gt;》页面中查看。&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/jquery-plugin-development.htm&quot; title=&quot;JQuery插件开发&quot;&gt;JQuery插件开发&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/jquery-web-page-anchor-scoll-show.htm&quot; title=&quot;jQuery代码实现Web页内锚点scoll效果&quot;&gt;jQuery代码实现Web页内锚点scoll效果&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/jquery-return-top-code.htm&quot; title=&quot;JQuery返回顶部 代码 (wordpress)&quot;&gt;JQuery返回顶部 代码 (wordpress)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373423/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/jquery-tinylightbox-plugin.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/jquery-tinylightbox-plugin.htm/feed</wfw:commentRss><slash:comments>1</slash:comments><description>话说这是我目前博客中所使用的一个图片高亮弹出插件，只因功能单纯，代码短小，用着不错，写篇博文，简单总结一下。 效果如下图： 该插件的作用具体作用就是：当鼠标单击上图的第一张图片时，页面将会变成如下效果：高亮显示你所单击的图片。 有关该插件的使用详情，可到《tinyLightbox中文使用讲解》页面中查看。 相关文章JQuery插件开发jQuery代码实现Web页内锚点scoll效果JQuery返回顶部 代码 (wordpress)&lt;img src=&quot;http://www1.feedsky.com/t1/638373423/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/jquery-tinylightbox-plugin.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>Web前端</category><category>插件</category><category>tinyLightbox</category><category>jquery-tinyLightbox</category><category>JQuery</category><pubDate>Wed, 25 Apr 2012 00:10:47 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/jquery-tinylightbox-plugin.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=395</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/jquery-tinylightbox-plugin.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373423/6050201</fs:itemid></item><item><title>Javascript原生全屏API</title><link>http://www.crossyou.cn/native-fullscreen-javascript-api.htm</link><content:encoded>&lt;p&gt;HTML5中的&amp;lt;video&amp;gt;是一个相当不错的标签，然而在它刚发布的时候一个最大的问题就是它不能像Flash那样实现真正意义上的全屏，幸好接下来的几个月各大浏览器开始原生支持全屏。&lt;br /&gt;
&lt;span id=&quot;more-393&quot;&gt;&lt;/span&gt;&lt;br /&gt;
我花了一些时间在 &lt;a href=&quot;http://mediaelementjs.com/&quot;&gt;MediaElement.js HTML5 video player&lt;/a&gt; 中通过不同的方式来实现浏览器全屏，它在 Safari 5.1+, &lt;del&gt;&lt;a href=&quot;http://tools.google.com/dlpage/chromesxs&quot;&gt;Chrome Canary&lt;/a&gt;&lt;/del&gt; Chrome 15+, &lt;a href=&quot;http://nightly.mozilla.org/&quot;&gt;Firefox Nightly&lt;/a&gt;(到about:config中设置full-screen-api.enabled= true)，并且计划在Firefox10中原生实现这个接口。下面，我将试着解释一下这个API的支持情况，你也可以自己试着修改下面的代码进行测试。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://johndyer.name/lab/fullscreenapi/&quot;&gt;Simple Demo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://mediaelementjs.com/&quot;&gt;Video Demo&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;浏览器全屏API简史&lt;/h3&gt;
&lt;p&gt;1、第一个实现浏览器原生全屏API的是在Safari 5.0（和iOS）中添加的webkitEnterFullScreen()函数，不过它只能在Safar的&amp;lt;video&amp;gt;标签的controls中(参见： &lt;a href=&quot;http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/HTMLVideoElementClassReference/HTMLVideoElement/HTMLVideoElement.html&quot;&gt;Apple’s HTML5VideoElement&lt;/a&gt;)。&lt;/p&gt;
&lt;p&gt;2、在Safari 5.1中，苹果更新了这个API使它更接近于&lt;a href=&quot;https://wiki.mozilla.org/Gecko:FullScreenAPI&quot;&gt;Mozilla的全屏API草案&lt;/a&gt;(实际上这要比苹果实现的更早)，现在，所有的DOM元素都可以调用webkitRequestFullScreen()函数使HTML页面进入到全屏模式。&lt;/p&gt;
&lt;p&gt;3、Firefox和Chome宣布它们将会添加原生的全屏API支持，而且这个特性已经在Chome 15+以及&lt;a href=&quot;http://nightly.mozilla.org/&quot; target=&quot;_blank&quot;&gt;Firefox Nightly&lt;/a&gt;(Firefox10+)中实现,Mozilla团队已经发布了一些&lt;a href=&quot;http://pearce.org.nz/full-screen/&quot;&gt;演示&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;4、在2011年10月15日，W3C发布了一份全屏API草案（由Opera团队的一名成员编写），它跟Mozilla的草案有两个主要的不同点：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Mozilla/Webkit使用大写字母&amp;#8217;S'（FullScreen），但W3C则不是（Fullscreen）&lt;/li&gt;
&lt;li&gt;Mozilla/Webkit使用cancelFullScreen，W3C使用exitFullscreen&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;5、更新 (11/15/2011)：来自 &lt;a href=&quot;http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/blogs.msdn.com/b/ie/&quot;&gt;IEBlog&lt;/a&gt;的Ted Johnson说&lt;del&gt;IE10将不会支持全屏API&lt;/del&gt; (12/05/2011: 我对Ted的第一封email理解错了)IE10的开发团队还没有决定是否要实现全屏API。不过，他指出：Win8的 Metro风格的Internet Explorer始终是全屏状态，正如以前那样，按F11键即可进入全屏模式。&lt;/p&gt;
&lt;h3&gt;理解浏览器全屏API&lt;/h3&gt;
&lt;p&gt;这里是全屏API在不同浏览器中所记录的最重要的部分，一般情况下，下面的例子我都是使用Mozilla/Webkit进行代码的编写，但在必要的地方我也注意到了w3c的差异。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1、检测全屏支持&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;为了检测浏览全屏支持，你你需要使用typeof检测浏览器是否支持全屏API的方法，同时这也有一个fullScreenEnabled的属性，它将会告诉你是否禁用了该功能(奇怪的是如果禁用的该功能WebKit 就没有fullScreenEnabled这个属性，这将使检测变的困难)&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;// Mozilla's proposed API: in practice, you'll need vendor prefixes (see examples below)
if (typeof document.cancelFullScreen != 'undefined' &amp;amp;&amp;amp; document.fullScreenEnabled === true) {
    /* do fullscreen stuff */
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;2、进入和退出全屏&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;要进入全屏模式，可以调用需要进入全屏元素的requestFullScreen（或者W3C的 requestFullscreen）方法。。要退出全屏，则调用document对象的cancelFullScreen（或者W3C的exitFullscreen）方法。&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;// mozilla proposal
element.requestFullScreen();
document.cancelFullScreen(); 

// Webkit (works in Safari and Chrome Canary)
element.webkitRequestFullScreen();
document.webkitCancelFullScreen(); 

// Firefox (works in nightly)
element.mozRequestFullScreen();
document.mozCancelFullScreen(); 

// W3C Proposal
element.requestFullscreen();
document.exitFullscreen();&lt;/pre&gt;
&lt;p&gt;Mozilla还提供了一个备用的requestFullScreenWithKeys()方法让用户可以通过键盘进入全屏模式。在Flash中，Adobe一直在全屏状态时禁止键盘支持，以防止恶意网站试图窃取密码，但浏览器制造商似乎正考虑使之成为一个可选设置。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3、浏览器全屏事件和当前状态&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;要检测全屏事件的发生，可以监听元素的fullscreeneventchange事件，而document的布尔属性fullScreen会指明当前是否全屏状态。&lt;/p&gt;
&lt;pre  class=&quot;js&quot; name=&quot;code&quot;&gt;element.addEventListener('fullscreeneventchange', function(e) {
    if (document.fullScreen) {
       /* make it look good for fullscreen */
    } else {
       /* return to the normal state in page */
    }
}, true);&lt;/pre&gt;
&lt;p&gt;Mozilla也提到在将来增加一个fullscreendenied事件。另外，Webkit在全屏布尔属性的名字上加了&amp;#8217;Is&amp;#8217;,但是w3c草案没有包括这个属性。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4、浏览器全屏样式&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Mozilla和W3C都提供了新的伪CSS类来装饰元素的全屏模式。&lt;/p&gt;
&lt;pre class=&quot;css&quot; name=&quot;code&quot;&gt;/* normal state */
.my-container {
    width: 640px;
    height: 360px;
}

/* Mozilla proposal (dash) */
.my-container:full-screen {
    width:100%;
    height:100%;
}

/* W3C proposal (no dash) */
.my-container:fullscreen {
    width:100%;
    height:100%;
}

/* currently working vendor prefixes */
.my-container:-webkit-full-screen, .my-container:-moz-full-screen {
    width:100%;
    height:100%;
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;5、嵌套的浏览器全屏&lt;/strong&gt;&lt;br /&gt;
当你使用Flash的&amp;lt;object&amp;gt;、&amp;lt;embed&amp;gt;从其他站点嵌入内容（比如一个YouTuBe视频）是，你可以指定是否允许它们全屏。这个特性也通过&lt;strong&gt;allowFullScreen&lt;/strong&gt;属性添加到&amp;lt;iframe&amp;gt;标签。&lt;/p&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;!-- content from another site that is allowed to use the fullscreen command --&amp;gt;
&amp;lt;iframe src=&quot;http://anothersite.com/video/123&quot; width=&quot;640&quot; height=&quot;360&quot; allowFullScreen&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/pre&gt;
&lt;h3&gt;最终代码如下:&lt;/h3&gt;
&lt;p&gt;为了使其在当前状态下工作，你需要封装代码以检测浏览器对全屏API的支持情况，下面我将可以在Safari 5.1, Chrome Canary Chrome 15+, and Firefox Nightly运行的代码合并在了一起，我将会不断更新。&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;(function() {
    var fullScreenApi = {
            supportsFullScreen: false,
            isFullScreen: function() { return false; },
            requestFullScreen: function() {},
            cancelFullScreen: function() {},
            fullScreenEventName: '',
            prefix: ''
        },
        browserPrefixes = 'webkit moz o ms khtml'.split(' ');

    // check for native support
    if (typeof document.cancelFullScreen != 'undefined') {
        fullScreenApi.supportsFullScreen = true;
    } else {
        // check for fullscreen support by vendor prefix
        for (var i = 0, il = browserPrefixes.length; i &amp;lt; il; i++ ) {
            fullScreenApi.prefix = browserPrefixes[i];

            if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) {
                fullScreenApi.supportsFullScreen = true;

                break;
            }
        }
    }

    // update methods to do something useful
    if (fullScreenApi.supportsFullScreen) {
        fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';

        fullScreenApi.isFullScreen = function() {
            switch (this.prefix) {
                case '':
                    return document.fullScreen;
                case 'webkit':
                    return document.webkitIsFullScreen;
                default:
                    return document[this.prefix + 'FullScreen'];
            }
        }
        fullScreenApi.requestFullScreen = function(el) {
            return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();
        }
        fullScreenApi.cancelFullScreen = function(el) {
            return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen']();
        }
    }

    // jQuery plugin
    if (typeof jQuery != 'undefined') {
        jQuery.fn.requestFullScreen = function() {

            return this.each(function() {
                if (fullScreenApi.supportsFullScreen) {
                    fullScreenApi.requestFullScreen(this);
                }
            });
        };
    }

    // export api
    window.fullScreenApi = fullScreenApi;
})();&lt;/pre&gt;
&lt;p&gt;上面的代码创建了一个名叫fullScreenApi的对象，拥有一个supportsFullScreen属性和其他一些通用的方法，下面是一段示例代码：&lt;/p&gt;
&lt;pre class=&quot;js&quot; name=&quot;code&quot;&gt;if (fullScreenApi.supportsFullScreen) {
    myButton.addEventListener('click', function() {
        fullScreenApi.requestFullScreen(someElement);
    }, true);
}&lt;/pre&gt;
&lt;p&gt;翻译自：&lt;a href=&quot;http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/&quot;&gt;http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/&lt;/a&gt;&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; title=&quot;关于javascript数组去重的性能测试&quot;&gt;关于javascript数组去重的性能测试&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; title=&quot;Javascript数组去重 方法总结&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; title=&quot;mouseenter 和 mouseleave事件总结学习&quot;&gt;mouseenter 和 mouseleave事件总结学习&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-fifo-class.htm&quot; title=&quot;Javascript 先进先出队列类&quot;&gt;Javascript 先进先出队列类&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-recursion-function.htm&quot; title=&quot;Javascript 递归函数&quot;&gt;Javascript 递归函数&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373424/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/native-fullscreen-javascript-api.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>HTML5中的&amp;#60;video&amp;#62;是一个相当不错的标签，然而在它刚发布的时候一个最大的问题就是它不能像Flash那样实现真正意义上的全屏，幸好接下来的几个月各大浏览器开始原生支持全屏。 我花了一些时间在 MediaElement.js HTML5 video player 中通过不同的方式来实现浏览器全屏，它在 Safari 5.1+, Chrome Canary Chrome 15+, Firefox Nightly(到about:config中设置full-screen-api.enabled= true)，并且计划在Firefox10中原生实现这个接口。下面，我将试着解释一下这个API的支持情况，你也可以自己试着修改下面的代码进行测试。 Simple Demo Video Demo 浏览器全屏API简史 1、第一个实现浏览器原生全屏API的是在Safari 5.0（和iOS）中添加的webkitEnterFullScreen()函数，不过它只能在Safar的&amp;#60;video&amp;#62;标签的controls中(参见： Apple’s HTML5VideoElement)。 2、在Safari 5.1中，苹果更新了这个API使它更接近于Mozilla的全屏API草案(实际上这要比苹果实现的更早)，现在，所有的DOM元素都可以调用webkitRequestFullScreen()函数使HTML页面进入到全屏模式。 3、Firefox和Chome宣布它们将会添加原生的全屏API支持，而且这个特性已经在Chome 15+以及Firefox Nightly(Firefox10+)中实现,Mozilla团队已经发布了一些演示。 4、在2011年10月15日，W3C发布了一份全屏API草案（由Opera团队的一名成员编写），它跟Mozilla的草案有两个主要的不同点： Mozilla/Webkit使用大写字母&amp;#8217;S'（FullScreen），但W3C则不是（Fullscreen） Mozilla/Webkit使用cancelFullScreen，W3C使用exitFullscreen 5、更新 (11/15/2011)：来自 IEBlog的Ted Johnson说IE10将不会支持全屏API (12/05/2011: 我对Ted的第一封email理解错了)IE10的开发团队还没有决定是否要实现全屏API。不过，他指出：Win8的 Metro风格的Internet Explorer始终是全屏状态，正如以前那样，按F11键即可进入全屏模式。 理解浏览器全屏API 这里是全屏API在不同浏览器中所记录的最重要的部分，一般情况下，下面的例子我都是使用Mozilla/Webkit进行代码的编写，但在必要的地方我也注意到了w3c的差异。 1、检测全屏支持 为了检测浏览全屏支持，你你需要使用typeof检测浏览器是否支持全屏API的方法，同时这也有一个fullScreenEnabled的属性，它将会告诉你是否禁用了该功能(奇怪的是如果禁用的该功能WebKit 就没有fullScreenEnabled这个属性，这将使检测变的困难) // Mozilla's proposed API: in practice, you'll need vendor prefixes (see examples below) if (typeof document.cancelFullScreen != 'undefined' [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373424/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>全屏API</category><category>html5</category><category>Web前端</category><category>javascript</category><category>fullscreen</category><pubDate>Mon, 23 Apr 2012 14:10:10 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/native-fullscreen-javascript-api.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=393</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/native-fullscreen-javascript-api.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373424/6050201</fs:itemid></item><item><title>Javascript:使用Web代理实现XMLHttpRequest跨域访问</title><link>http://www.crossyou.cn/howto-proxy.htm</link><content:encoded>&lt;p&gt;XMLHttpRequest对象(在IE中也称作XMLHTTP对象)是当今最令人兴奋的AJAX Web应用程序的核心。但实际上使用这个对象书写的客户端web应用程序在通过web浏览器进行跨域访问时面临的安全限制性因素而变的非常棘手。这篇文章以简单易于理解的语言描述了这个问题，并提供了一个可行的解决方案：来自你的web服务器请求像雅虎的web服务API网络请求的web代理。&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-387&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;#why&quot;&gt;为什么需要代理&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;#phpproxy&quot;&gt;用PHP代理访问雅虎的Web服务&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;#other&quot;&gt;其他解决方案&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;#more&quot;&gt;了解更多信息&lt;/a&gt;&lt;/p&gt;
&lt;h3 style=&quot;color: #7B0099;margin: 1em 0 0.4em;&quot;&gt;为什么需要代理&lt;a name=&quot;why&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;所有现代的Web浏览器在网络连接上增加了安全性的限制，其中包括XMLHttpRequest调用。可中安全性限制可以防止脚本或应用程序访问和操作另外一个域的属性和方法(在IE浏览器中的首选参数中如果该选项被设置为可用，则允许跨域请求)。如果你的Web应用程序和应用程序所需的XML数据都是来自同一个服务器，则不会有这种限制。&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignleft size-full wp-image-388&quot; title=&quot;proxy1&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/proxy1.gif&quot; alt=&quot;&quot; width=&quot;336&quot; height=&quot;189&quot; /&gt;&lt;/p&gt;
&lt;p&gt;然而，如果你要为你的web应用程序提供其他服务器上的服务，例如，雅虎的Web服务，那么浏览器将会阻止这种访问&lt;br /&gt;
&lt;img class=&quot;alignleft size-full wp-image-389&quot; title=&quot;proxy2&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/proxy2.gif&quot; alt=&quot;&quot; width=&quot;347&quot; height=&quot;284&quot; /&gt;。&lt;/p&gt;
&lt;p&gt;这里有不少解决这个问题的方案，但最常用的是在你的Web服务器上使用代理，这样你就不需要使用XMLHttpRequest对象直接访问雅虎的Web服务，而是去访问你的web服务器上的代理服务，这个代理可以根据你的请求去调用雅虎的Web服务，并将请求返回的数据返回到客户端，因为XMLHttpRequest请求的是你自己的服务器，因此就不会存在浏览器的安全性限制问题。&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignleft size-full wp-image-390&quot; title=&quot;proxy3&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/proxy3.gif&quot; alt=&quot;&quot; width=&quot;525&quot; height=&quot;201&quot; /&gt;&lt;/p&gt;
&lt;p&gt;出于安全因素，在你web服务器上使用代理访问服务应该使用有所限制的，一个连接到任何网站的URL的开发代理是很容易被滥用的。虽然很难限制只用你的应用程序连接到代理，但是你可以在代理服务器上指定代理所能访问的服务.&lt;/p&gt;
&lt;h3 style=&quot;color: #7B0099;margin: 1em 0 0.4em;&quot;&gt;用PHP代理访问雅虎的Web服务&lt;a name=&quot;phpproxy&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;在&lt;a href=&quot;http://developer.yahoo.com/javascript/index.html&quot;&gt;JavaScript Developer Center&lt;/a&gt;提供了一段用PHP写的&lt;a href=&quot;http://developer.yahoo.com/javascript/samples/proxy/php_proxy_simple.txt&quot;&gt;简单web代理&lt;/a&gt;，它是用来代理访问雅虎的搜索服务API的,你可以将这段简单的Web代理代码拷贝到你Web服务的的任意方便的位置，前提是你的Web服务可以运行PHP程序。&lt;/p&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;define ('HOSTNAME', 'http://search.yahooapis.com/');&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://developer.yahoo.com/javascript/samples/ajax/sample_proxy_ajax.html&quot;&gt;more complete XMLHttpRequest code sample&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;然后你的客户端就可以像下面这样使用XMLHttpRequest进行访问了&lt;/p&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;// The web services request minus the domain name
var path = 'VideoSearchService/V1/videoSearch?appid=YahooDemo&amp;amp;query=madonna&amp;amp;results=2';

// The full path to the PHP proxy
var url = 'http://localhost/php_proxy_simple.php?yws_path=' + encodeURIComponent(path);
... // core xmlhttp code
xmlhttp.open('GET', url, true);&lt;/pre&gt;
&lt;h3 style=&quot;color: #7B0099;margin: 1em 0 0.4em;&quot;&gt;其他解决方案&lt;a name=&quot;other&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;除了使用Web代理可以传输web服务数据到你的web应用程序，这里还用几种绕过浏览跨域访问限制的方法：&lt;/p&gt;
&lt;p&gt;1，使用apache的 mod_rewrite or mod_proxy模块转发对你服务器的请求到其他服务器。&lt;/p&gt;
&lt;p&gt;2，使用JSON和动态的&amp;lt;script&amp;gt;标签来代替XMLHttpRequest，也就是所谓的JSONP。&lt;/p&gt;
&lt;p&gt;3，Digitally sign your scripts，这种方式只在Firefox浏览器中可以使用，其他浏览器不可用。&lt;/p&gt;
&lt;h3 style=&quot;color: #7B0099;margin: 1em 0 0.4em;&quot;&gt;了解更多信息&lt;a name=&quot;more&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;想对JavaScript, XMLHttpRequest, Yahoo! Web Services APIs以及其他javascript开发的话题，访问The Yahoo! Developer Network &lt;a href=&quot;http://developer.yahoo.com/javascript/index.html&quot;&gt;JavaScript Developer Center&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;英文地址：&lt;a href=&quot;http://developer.yahoo.com/javascript/howto-proxy.html&quot;&gt;http://developer.yahoo.com/javascript/howto-proxy.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;翻译的不好，莫喷，实际上本文介绍的方法，也是笔者经常使用的一种方法，其实就是使用PHP中的CURL模块，在服务端模拟浏览器的请求动作实现服务的代理。&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/php%ef%bc%9aimg-base64.htm&quot; title=&quot;PHP：将图片编码成base64&quot;&gt;PHP：将图片编码成base64&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; title=&quot;关于javascript数组去重的性能测试&quot;&gt;关于javascript数组去重的性能测试&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; title=&quot;Javascript数组去重 方法总结&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; title=&quot;Javascript原生全屏API&quot;&gt;Javascript原生全屏API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; title=&quot;mouseenter 和 mouseleave事件总结学习&quot;&gt;mouseenter 和 mouseleave事件总结学习&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-fifo-class.htm&quot; title=&quot;Javascript 先进先出队列类&quot;&gt;Javascript 先进先出队列类&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373425/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/howto-proxy.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/howto-proxy.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>XMLHttpRequest对象(在IE中也称作XMLHTTP对象)是当今最令人兴奋的AJAX Web应用程序的核心。但实际上使用这个对象书写的客户端web应用程序在通过web浏览器进行跨域访问时面临的安全限制性因素而变的非常棘手。这篇文章以简单易于理解的语言描述了这个问题，并提供了一个可行的解决方案：来自你的web服务器请求像雅虎的web服务API网络请求的web代理。 为什么需要代理 用PHP代理访问雅虎的Web服务 其他解决方案 了解更多信息 为什么需要代理 所有现代的Web浏览器在网络连接上增加了安全性的限制，其中包括XMLHttpRequest调用。可中安全性限制可以防止脚本或应用程序访问和操作另外一个域的属性和方法(在IE浏览器中的首选参数中如果该选项被设置为可用，则允许跨域请求)。如果你的Web应用程序和应用程序所需的XML数据都是来自同一个服务器，则不会有这种限制。 然而，如果你要为你的web应用程序提供其他服务器上的服务，例如，雅虎的Web服务，那么浏览器将会阻止这种访问 。 这里有不少解决这个问题的方案，但最常用的是在你的Web服务器上使用代理，这样你就不需要使用XMLHttpRequest对象直接访问雅虎的Web服务，而是去访问你的web服务器上的代理服务，这个代理可以根据你的请求去调用雅虎的Web服务，并将请求返回的数据返回到客户端，因为XMLHttpRequest请求的是你自己的服务器，因此就不会存在浏览器的安全性限制问题。 出于安全因素，在你web服务器上使用代理访问服务应该使用有所限制的，一个连接到任何网站的URL的开发代理是很容易被滥用的。虽然很难限制只用你的应用程序连接到代理，但是你可以在代理服务器上指定代理所能访问的服务. 用PHP代理访问雅虎的Web服务 在JavaScript Developer Center提供了一段用PHP写的简单web代理，它是用来代理访问雅虎的搜索服务API的,你可以将这段简单的Web代理代码拷贝到你Web服务的的任意方便的位置，前提是你的Web服务可以运行PHP程序。 define ('HOSTNAME', 'http://search.yahooapis.com/'); more complete XMLHttpRequest code sample 然后你的客户端就可以像下面这样使用XMLHttpRequest进行访问了 // The web services request minus the domain name var path = 'VideoSearchService/V1/videoSearch?appid=YahooDemo&amp;#38;query=madonna&amp;#38;results=2'; // The full path to the PHP proxy var url = 'http://localhost/php_proxy_simple.php?yws_path=' + encodeURIComponent(path); ... // core [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373425/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/howto-proxy.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>跨域</category><category>Web前端</category><category>php</category><category>XMLHttpRequest</category><category>javascript</category><category>curl</category><pubDate>Sun, 22 Apr 2012 23:00:48 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/howto-proxy.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=387</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/howto-proxy.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373425/6050201</fs:itemid></item><item><title>mouseenter 和 mouseleave事件总结学习</title><link>http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm</link><content:encoded>&lt;p&gt;现在除IE系列支持mouseenter 和 mouseleave事件外，opera11+ 、firefox10+也支持mouseenter 和 mouseleave事件，同时它们也成为w3c DOM3 Event的规范，&lt;a title=&quot;司徒正美的博客园&quot; href=&quot;http://www.cnblogs.com/rubylouvre/&quot;&gt;司徒正美&lt;/a&gt;的框架中有比较详细的说明哈。&lt;br /&gt;
&lt;span id=&quot;more-382&quot;&gt;&lt;/span&gt;&lt;br /&gt;
话说这两个事件之前也遇到过，只是没太在意，至今别人提起的时候，才觉得这两个事件的重要性，身为Web前端开发人员，表示惭愧。&lt;/p&gt;
&lt;p&gt;一般都是拿这两个事件和 mouseover、mouseout事件进行比较，两者最大的区别就是 mouseenter/mouseleave 不冒泡的事件，那么两者的这种不同之处的具体表现是什么？ 请观看下方Demo：&lt;/p&gt;
&lt;p&gt;&lt;a title=&quot;mouseenter 和 mouseleave事件总结&quot; href=&quot;http://static.crossyou.cn/study/mouseenter-mouseleave-event.html&quot;&gt;http://static.crossyou.cn/study/mouseenter-mouseleave-event.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;截图说明：&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignleft size-full wp-image-384&quot; title=&quot;mouseenter&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/mouseenter.png&quot; alt=&quot;&quot; width=&quot;388&quot; height=&quot;128&quot; /&gt;&lt;/p&gt;
&lt;p&gt;上图所示：为红A所处的div添加mouseenter 和 mouseleave事件，那么当鼠标从A的外面移入到B内部的过程中将会依次触发：&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;1、mouseenter事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;当鼠标从B内部移动到A外部区域的过程中将会依次触发：&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;1、mouseleave事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignleft size-full wp-image-386&quot; title=&quot;mouseover&quot; src=&quot;http://static.crossyou.cn/wordpress/media/2012/04/mouseover1.png&quot; alt=&quot;&quot; width=&quot;401&quot; height=&quot;127&quot; /&gt;&lt;/p&gt;
&lt;p&gt;上图所示：为红C所处的div添加mouseover和 mouseout事件，那么当鼠标从C的外部移入到D内部的过程中将会依次触发：&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;1、mouseover事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;2、mouseout事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;3、mouseover事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;而当鼠标从D内部移动到C外部区域的过程中则将会依次触发：&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;1、mouseout事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;2、mouseover事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #7b0099;&quot;&gt;3、mouseout事件&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;可以看到mouseover和mouseout事件冒泡了，而mouseenter和mouseleave事件则没有冒泡。&lt;/p&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; title=&quot;关于javascript数组去重的性能测试&quot;&gt;关于javascript数组去重的性能测试&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; title=&quot;Javascript数组去重 方法总结&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; title=&quot;Javascript原生全屏API&quot;&gt;Javascript原生全屏API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-fifo-class.htm&quot; title=&quot;Javascript 先进先出队列类&quot;&gt;Javascript 先进先出队列类&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-recursion-function.htm&quot; title=&quot;Javascript 递归函数&quot;&gt;Javascript 递归函数&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373426/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>现在除IE系列支持mouseenter 和 mouseleave事件外，opera11+ 、firefox10+也支持mouseenter 和 mouseleave事件，同时它们也成为w3c DOM3 Event的规范，司徒正美的框架中有比较详细的说明哈。 话说这两个事件之前也遇到过，只是没太在意，至今别人提起的时候，才觉得这两个事件的重要性，身为Web前端开发人员，表示惭愧。 一般都是拿这两个事件和 mouseover、mouseout事件进行比较，两者最大的区别就是 mouseenter/mouseleave 不冒泡的事件，那么两者的这种不同之处的具体表现是什么？ 请观看下方Demo： http://static.crossyou.cn/study/mouseenter-mouseleave-event.html 截图说明： 上图所示：为红A所处的div添加mouseenter 和 mouseleave事件，那么当鼠标从A的外面移入到B内部的过程中将会依次触发： 1、mouseenter事件 当鼠标从B内部移动到A外部区域的过程中将会依次触发： 1、mouseleave事件 上图所示：为红C所处的div添加mouseover和 mouseout事件，那么当鼠标从C的外部移入到D内部的过程中将会依次触发： 1、mouseover事件 2、mouseout事件 3、mouseover事件 而当鼠标从D内部移动到C外部区域的过程中则将会依次触发： 1、mouseout事件 2、mouseover事件 3、mouseout事件 可以看到mouseover和mouseout事件冒泡了，而mouseenter和mouseleave事件则没有冒泡。 相关文章关于javascript数组去重的性能测试Javascript数组去重 方法总结Javascript原生全屏APIJavascript:使用Web代理实现XMLHttpRequest跨域访问Javascript 先进先出队列类Javascript 递归函数&lt;img src=&quot;http://www1.feedsky.com/t1/638373426/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>mouseout</category><category>Web前端</category><category>mouseenter</category><category>mouseover</category><category>javascript</category><category>mouseleave</category><pubDate>Sat, 21 Apr 2012 19:32:03 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=382</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373426/6050201</fs:itemid></item><item><title>Javascript 先进先出队列类</title><link>http://www.crossyou.cn/javascript-fifo-class.htm</link><content:encoded>&lt;blockquote&gt;&lt;p&gt;队列，FIFO(First Input First Output) 一种先进先出的数据缓存器。&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span id=&quot;more-379&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;javascript&quot; name=&quot;code&quot;&gt;
(function(){
	function Array_h(length){
		this.array = length === undefined ? [] : new Array(length);
	}
	Array_h.prototype = {
		/**
		 * 返回数组长度
		 *
		 * @return {Number} length [数组长度]
		 */
		length: function() {
			return this.array.length;
		},

		at: function(index) {
			return this.array[index];
		},

		set: function(index, obj) {
			this.array[index] = obj;
		},

		/**
		 * 向数组的末尾添加一个或多个元素，并返回新的长度。
		 *
		 * @param  {*} obj [description]
		 * @return {Number} length [新数组的长度]
		 */
		push: function(obj) {
			return this.array.push(obj);
		},

		/**
		 * 返回数组中选定的元素
		 *
		 * @param  {Number} start [开始索引值]
		 * @param  {Number} end [结束索引值]
		 * @return {Array} newArray  [新的数组]
		 */
		slice: function(start, end) {
			return this.array = this.array.slice(start, end);
		},

		concat: function(array) {
			this.array = this.array.concat(array);
		},

		remove: function(index, count) {
			count = count === undefined ? 1 : count;
			this.array.splice(index, count);
	    },

		join: function(separator) {
			return this.array.join(separator);
		},

		clear: function() {
			this.array.length = 0;
		}
	}

	/**
	 * 先进先出队列 (First Input First Output)
	 *
	 * 一种先进先出的数据缓存器
	 */
	function Queue(){
		this._array_h = new Array_h();
	};

	Queue.prototype = {
		_index: 0,

		/**
		 * 排队
		 *
		 * @param  {Object} obj [description]
		 * @return {[type]}     [description]
		 */
		push: function(obj) {
			this._array_h.push(obj);
		},

		/**
		 * 出队
		 *
		 * @return {Object} [description]
		 */
		pop: function() {
			var ret = null;
			if (this._array_h.length()) {
				ret = this._array_h.at(this._index);
				if (++this._index * 2 &gt;= this._array_h.length()) {
					this._array_h.slice(this._index);
					this._index = 0;
				}
			}
			return ret;
		},

		/**
		 * 返回队列中头部(即最新添加的)的动态对象
		 *
		 * @return {Object} [description]
		 */
		head: function() {
			var ret = null, len = this._array_h.length();
			if (len) {
				ret = this._array_h.at(len - 1);
			}
			return ret;
		},

		/**
		 * 返回队列中尾部(即最早添加的)的动态对象
		 *
		 * @return {Object} [description]
		 */
		tail: function(){
			var ret = null, len = this._array_h.length();
			if (len) {
				ret = this._array_h.at(this._index);
			}
			return ret;
		},

		/**
		 * 返回数据队列长度
		 *
		 * @return {Number} [description]
		 */
		length: function() {
			return this._array_h.length() - this._index;
		},

		/**
		 * 队列是否为空
		 *
		 * @return {Boolean} [description]
		 */
		empty: function() {
			return (this._array_h.length() === 0);
		},

		clear: function(){
			this._array_h.clear();
		}
	};

	var queue = new Queue();

	queue.push('one');
	queue.push('two');
	queue.push('three');

	console.log(queue.head());// three
	console.log(queue.tail());// one
	console.log(queue.length());// 3

	queue.pop();

	console.log(queue.head());// three
	console.log(queue.tail());// two
	console.log(queue.length());// 2

	queue.clear()//清空队列数据

	console.log(queue.head());// null
	console.log(queue.tail());// null
	console.log(queue.length());// -1
})();
&lt;/pre&gt;
&lt;h4  class=&quot;related_post_title&quot;&gt;相关文章&lt;/h4&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-array-to-re-performance-testing.htm&quot; title=&quot;关于javascript数组去重的性能测试&quot;&gt;关于javascript数组去重的性能测试&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-no-repeat-method.htm&quot; title=&quot;Javascript数组去重 方法总结&quot;&gt;Javascript数组去重 方法总结&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/native-fullscreen-javascript-api.htm&quot; title=&quot;Javascript原生全屏API&quot;&gt;Javascript原生全屏API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/howto-proxy.htm&quot; title=&quot;Javascript:使用Web代理实现XMLHttpRequest跨域访问&quot;&gt;Javascript:使用Web代理实现XMLHttpRequest跨域访问&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/mouseenter-and-mouseleave-event-summary-of-learning.htm&quot; title=&quot;mouseenter 和 mouseleave事件总结学习&quot;&gt;mouseenter 和 mouseleave事件总结学习&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.crossyou.cn/javascript-recursion-function.htm&quot; title=&quot;Javascript 递归函数&quot;&gt;Javascript 递归函数&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/638373427/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-fifo-class.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://www.crossyou.cn/javascript-fifo-class.htm/feed</wfw:commentRss><slash:comments>0</slash:comments><description>队列，FIFO(First Input First Output) 一种先进先出的数据缓存器。 (function(){ function Array_h(length){ this.array = length === undefined ? [] : new Array(length); } Array_h.prototype = { /** * 返回数组长度 * * @return {Number} length [数组长度] */ length: function() { return this.array.length; }, at: function(index) { return this.array[index]; }, set: function(index, obj) { this.array[index] = obj; }, /** * 向数组的末尾添加一个或多个元素，并返回新的长度。 [...]&lt;img src=&quot;http://www1.feedsky.com/t1/638373427/crossyou2009/feedsky/s.gif?r=http://www.crossyou.cn/javascript-fifo-class.htm&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>Web前端</category><category>先进先出</category><category>fifo</category><category>javascript</category><pubDate>Tue, 17 Apr 2012 13:56:25 +0800</pubDate><author>CrossYou</author><comments>http://www.crossyou.cn/javascript-fifo-class.htm#comments</comments><guid isPermaLink="false">http://www.crossyou.cn/?p=379</guid><dc:creator>CrossYou</dc:creator><fs:srclink>http://www.crossyou.cn/javascript-fifo-class.htm</fs:srclink><fs:srcfeed>http://crossyou.cn/feed</fs:srcfeed><fs:itemid>feedsky/crossyou2009/~7940334/638373427/6050201</fs:itemid></item></channel></rss>
