﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-f(sixleaves) = sixleaves-随笔分类-Web</title><link>http://www.cppblog.com/sixleaves/category/20825.html</link><description>重剑无锋 大巧不工</description><language>zh-cn</language><lastBuildDate>Sat, 23 Aug 2014 06:02:01 GMT</lastBuildDate><pubDate>Sat, 23 Aug 2014 06:02:01 GMT</pubDate><ttl>60</ttl><item><title>JS(04)图片库改进之书写优秀的JS-DOM</title><link>http://www.cppblog.com/sixleaves/archive/2014/07/11/207609.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Thu, 10 Jul 2014 18:41:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/07/11/207609.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/207609.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/07/11/207609.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/207609.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/207609.html</trackback:ping><description><![CDATA[<span style="font-size: 12pt;">今天完成了图片库的改进，不得写下关于这个的深切感触，获得的宝贵经验！。不罗嗦直接看先看代码</span><br /><span style="font-size: 12pt;">1.平稳退化</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; 要支持平稳退化，也就是在浏览器禁用js时，不会造成无法浏览，知识用户体验变差了而已，功能还是实现了的。此时就不能使用javascript伪协议加href属性来解决。如下。</span><br /><span style="font-size: 12pt;">2.分离js</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;"> 分离js的关键技术就是要结合HTML生命周期，和window对象的onload方法以及元素对象拥有事件函数进行相应的自定义函数绑定。</span><br /><span style="font-size: 12pt;">3.兼容性（对象检查技术、其实用来确定代码错误位置也很好用）</span><br /><span style="font-size: 12pt;">4.优化代码(使用特定压缩工具，压缩js代码)</span><br />
<span style="font-size: 12pt; color: #008080;">&nbsp;1</span><span style="font-size: 13px; background-color: #eeeeee;">&nbsp;</span><span style="font-size: 12pt; color: #0000ff;">&lt;!</span><span style="font-size: 12pt; color: #ff00ff;">DOCTYPE&nbsp;html</span><span style="font-size: 12pt; color: #0000ff;">&gt;</span><br />
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #008080; font-size: 12pt;">&nbsp;2</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">html</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">head</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">meta&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">charset</span><span style="color: #0000ff; font-size: 12pt;">="utf-8"</span><span style="color: #FF0000; ">&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">/&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">title</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><span style="font-size: 12pt;">Image&nbsp;Gallery</span><span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">title</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">head</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">body</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">h1</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><span style="font-size: 12pt;">Snapshots</span><span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">h1</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">ul&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">id&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">=&nbsp;"imagegallery"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">11</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">a&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">href</span><span style="color: #0000ff; font-size: 12pt;">="images/fireworks.jpg"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;title</span><span style="color: #0000ff; font-size: 12pt;">="A&nbsp;fireworks&nbsp;display"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">12</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fireworks</span><br />
<span style="color: #008080; font-size: 12pt;">13</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">a</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">14</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">15</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">16</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">a&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">href</span><span style="color: #0000ff; font-size: 12pt;">="images/coffee.jpg"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;title</span><span style="color: #0000ff; font-size: 12pt;">="A&nbsp;cup&nbsp;of&nbsp;black&nbsp;coffee"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">17</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Coffee</span><br />
<span style="color: #008080; font-size: 12pt;">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">a</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">19</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">20</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">a&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">href</span><span style="color: #0000ff; font-size: 12pt;">="images/rose.jpg"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;title</span><span style="color: #0000ff; font-size: 12pt;">="A&nbsp;red.&nbsp;red&nbsp;rose"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">22</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rose</span><br />
<span style="color: #008080; font-size: 12pt;">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">a</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">24</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">25</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">26</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">a&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">href</span><span style="color: #0000ff; font-size: 12pt;">="images/bigben.jpg"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;title</span><span style="color: #0000ff; font-size: 12pt;">="The&nbsp;famous&nbsp;clock"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">27</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Big&nbsp;Ben</span><br />
<span style="color: #008080; font-size: 12pt;">28</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">a</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">29</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">li</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">30</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">ul</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">31</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">img&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">id</span><span style="color: #0000ff; font-size: 12pt;">="placeholder"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;src</span><span style="color: #0000ff; font-size: 12pt;">="images/placeholder.jpg"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;alt</span><span style="color: #0000ff; font-size: 12pt;">="my&nbsp;image&nbsp;gallery"</span><span style="color: #FF0000; ">&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">/&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">32</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">p&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">id</span><span style="color: #0000ff; font-size: 12pt;">="desp"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><span style="font-size: 12pt;">Choose&nbsp;an&nbsp;Image</span><span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">p</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">33</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;</span><span style="color: #800000; font-size: 12pt;">script&nbsp;</span><span style="color: #ff0000; font-size: 12pt;">type</span><span style="color: #0000ff; font-size: 12pt;">="text/javascript"</span><span style="color: #ff0000; font-size: 12pt;">&nbsp;src</span><span style="color: #0000ff; font-size: 12pt;">="./scripts/showPic.js"</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><span style="background-color: #f5f5f5;"><br />
</span><span style="color: #008080; font-size: 12pt;">34</span>&nbsp;<span style="background-color: #f5f5f5;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">script</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">35</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">body</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">36</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">&lt;/</span><span style="color: #800000; font-size: 12pt;">html</span><span style="color: #0000ff; font-size: 12pt;">&gt;</span></div><span style="font-size: 12pt;">
g</span><span style="font-size: 12pt; color: #008080;">&nbsp;1</span><span style="font-size: 13px; background-color: #eeeeee;">&nbsp;</span><span style="font-size: 12pt; color: #0000ff;">function</span><span style="font-size: 12pt; background-color: #eeeeee;">&nbsp;showPic(whichPic)&nbsp;{</span><br />
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #008080; font-size: 12pt;">&nbsp;2</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("showPic");</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;source&nbsp;=&nbsp;whichPic.getAttribute("href");</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;placeholder&nbsp;=&nbsp;document.getElementById("placeholder");</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;5</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;placeholder.setAttribute("src",source);</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;text&nbsp;=&nbsp;whichPic.getAttribute("title");</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;txtNode&nbsp;=&nbsp;document.getElementById("desp").firstChild;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;8</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txtNode.nodeValue&nbsp;=&nbsp;text;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">return</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">false</span><span style="font-size: 12pt;">;</span><br />
<span style="color: #008080; font-size: 12pt;">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">/*</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">11</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;经验总结:<br />
</span><span style="color: #008080; font-size: 12pt;">12</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.由于js是动态语言，所以存在一个很严重的问题，<br />
</span><span style="color: #008080; font-size: 12pt;">13</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那就是你自己取的变量名称时，尽可能的采用骆驼峰写法，<br />
</span><span style="color: #008080; font-size: 12pt;">14</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;并且最后借助好的编辑器，有自动补全功能的编辑器，一面<br />
</span><span style="color: #008080; font-size: 12pt;">15</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;拼写错误，这种错误低级，而且查找起来十分困难。<br />
</span><span style="color: #008080; font-size: 12pt;">16</span>&nbsp;<span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">17</span>&nbsp;<span style="color: #008000; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.如果站点用到多个js文件，因该把它合并到一个文件中。以减少请求次数，提高性能。<br />
</span><span style="color: #008080; font-size: 12pt;">18</span>&nbsp;<span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">19</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-size: 12pt;">*/</span><br />
<span style="color: #008080; font-size: 12pt;">20</span><span style="font-size: 12pt;">&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">21</span>&nbsp;<br />
<span style="color: #008080; font-size: 12pt;">22</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">function</span><span style="font-size: 12pt;">&nbsp;addLoadEvent(func)&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;oldLoad&nbsp;=&nbsp;window.onload;</span><br />
<span style="color: #008080; font-size: 12pt;">24</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">if</span><span style="font-size: 12pt;">(</span><span style="color: #0000ff; font-size: 12pt;">typeof</span><span style="font-size: 12pt;">&nbsp;oldLoad&nbsp;==&nbsp;'</span><span style="color: #0000ff; font-size: 12pt;">function</span><span style="font-size: 12pt;">')&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">25</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.onload&nbsp;=&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">function</span><span style="font-size: 12pt;">()&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">26</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oldLoad();</span><br />
<span style="color: #008080; font-size: 12pt;">27</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func();</span><br />
<span style="color: #008080; font-size: 12pt;">28</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">29</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff; font-size: 12pt;">else</span><span style="font-size: 12pt;">&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">30</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.onload&nbsp;=&nbsp;func;</span><br />
<span style="color: #008080; font-size: 12pt;">31</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">32</span><span style="font-size: 12pt;">&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">33</span>&nbsp;<br />
<span style="color: #008080; font-size: 12pt;">34</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">function</span><span style="font-size: 12pt;">&nbsp;prepareGallery()&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">35</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">使用对象检查技术，检查所要用到的方法是否可以用。</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">36</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">在js&nbsp;dom中，一切都可视为对象，包括方法，</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">37</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">所以说这是对象检测技术，检测这个对象存不存在</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">38</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">下面主要是检查浏览器是否支持这些DOM接口</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">39</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">alert("jsss");</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">40</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<span style="color: #008080; font-size: 12pt;">41</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">if</span><span style="font-size: 12pt;">(!document.getElementsByTagName)&nbsp;{alert("tag");</span><span style="color: #0000ff; font-size: 12pt;">return</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">false</span><span style="font-size: 12pt;">};</span><br />
<span style="color: #008080; font-size: 12pt;">42</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">if</span><span style="font-size: 12pt;">(!document.getElementById)&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">return</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">false</span><span style="font-size: 12pt;">;</span><br />
<span style="color: #008080; font-size: 12pt;">43</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">if</span><span style="font-size: 12pt;">(!document.getElementById("imagegallery"))&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">return</span>&nbsp;<span style="color: #0000ff; font-size: 12pt;">false</span><span style="font-size: 12pt;">;</span><br />
<span style="color: #008080; font-size: 12pt;">44</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;gl&nbsp;=&nbsp;document.getElementById("imagegallery");</span><br />
<span style="color: #008080; font-size: 12pt;">45</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;links&nbsp;=&nbsp;gl.getElementsByTagName("a");</span><br />
<span style="color: #008080; font-size: 12pt;">46</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">alert(typeof&nbsp;links);</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">47</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">for</span><span style="font-size: 12pt;">(</span><span style="color: #0000ff; font-size: 12pt;">var</span><span style="font-size: 12pt;">&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;links.length;&nbsp;i++)&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">48</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;links[i].onclick&nbsp;=&nbsp;</span><span style="color: #0000ff; font-size: 12pt;">function</span><span style="font-size: 12pt;">()&nbsp;{</span><br />
<span style="color: #008080; font-size: 12pt;">49</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-size: 12pt;">return</span><span style="font-size: 12pt;">&nbsp;showPic(</span><span style="color: #0000ff; font-size: 12pt;">this</span><span style="font-size: 12pt;">);</span><br />
<span style="color: #008080; font-size: 12pt;">50</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">51</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br />
<span style="color: #008080; font-size: 12pt;">52</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">alert("end");</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">53</span>&nbsp;<span style="color: #008000; "></span><span style="font-size: 12pt;">}</span><br />
<span style="color: #008080; font-size: 12pt;">54</span><span style="font-size: 12pt;">&nbsp;addLoadEvent(prepareGallery);</span><br />
<span style="color: #008080; font-size: 12pt;">55</span>&nbsp;<span style="color: #008000; font-size: 12pt;">/*</span><span style="color: #008000; "><br />
</span><span style="color: #008080; font-size: 12pt;">56</span>&nbsp;<span style="color: #008000; font-size: 12pt;">这里介绍下HTML的声明周期，当HTML文档完成加载时，此时DOM节点树立即构建起来，此时会出发window对象的onload事件<br />
</span><span style="color: #008080; font-size: 12pt;">57</span>&nbsp;<span style="color: #008000; font-size: 12pt;">所以我们在这个时候执行prepareGallery()函数进行，相应节点对象上的事件绑定是最合适的，因为此时我们能确保整颗节点<br />
</span><span style="color: #008080; font-size: 12pt;">58</span>&nbsp;<span style="color: #008000; font-size: 12pt;">树已经构建完毕，我们绑定只要代码不出错，就肯定不会出错。要是不用这个事件来处理。而只是通过srcipt标签引入，不管是放在<br />
</span><span style="color: #008080; font-size: 12pt;">59</span>&nbsp;<span style="color: #008000; font-size: 12pt;">head区域还是body结束之前，都无法保证此时DOM节点树已经构建完成，所以要实现js分离我们一定要用到HTML的声明周期中的加载完成<br />
</span><span style="color: #008080; font-size: 12pt;">60</span>&nbsp;<span style="color: #008000; font-size: 12pt;">，构建完成DOM节点树而触发的window.onload事件，有人会问此时document对象是否存在，在BOM中，window对象含有一个成员变量，<br />
</span><span style="color: #008080; font-size: 12pt;">61</span>&nbsp;<span style="color: #008000; font-size: 12pt;">就是document，所以有window对象，就有document对象。<br />
</span><span style="color: #008080; font-size: 12pt;">62</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; font-size: 12pt;">*/</span><br />
<span style="color: #008080; ">63</span>&nbsp;</div>
g<br /><span style="font-size: 12pt;">代码中的注释已经详细说明了代码是要来干什么的。其实今天改进版本的图片库，本来是想学习下HTML生命周期和DOM节点树的关系，以及和window.onload的关联。还有学习怎么平稳退化。结果卡壳，卡了半天，差错，差了半天，起初是其中一个字符编码有问题，运行结果不对。找了半天才找到。</span><br /><span style="font-size: 12pt;">这里总结写js的快速调试办法，当然有点麻烦。</span><br /><span style="font-size: 12pt;">我们在写js时，如果在定位元素时，我们应该分步定位，步步缩进，在定位时，</span><span style="font-size: 12pt; color: #ff0000;">利用对象检查技术，我们可以很轻易找到我们出错的地方</span><span style="font-size: 12pt;">。本来这项技术是用来保证兼容性的，但是我们还可以用它来定位错误！，</span><span style="font-size: 12pt; color: #ff0000;">在没有该对象的时候使用alert进行提示。在调试时，我们就可以快速定位错误的位置，</span><span style="font-size: 12pt;">因为大多数时候我们写的代码在我们理解的逻辑上是不会有错的，但是我们有时可能为定位某个元素，给其加了给id，但是定位时却拼错了，这时我们通过对象检查技术，就可以很快找到错误的地方。</span><br /><span style="font-size: 12pt;">2014.07.11</span><br /><span style="font-size: 12pt;">02：44</span><br /><span style="font-size: 12pt;">于福州 </span><img src ="http://www.cppblog.com/sixleaves/aggbug/207609.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-07-11 02:41 <a href="http://www.cppblog.com/sixleaves/archive/2014/07/11/207609.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JS(03) Node节点属性和事件之图片库</title><link>http://www.cppblog.com/sixleaves/archive/2014/07/10/207596.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Wed, 09 Jul 2014 18:53:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/07/10/207596.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/207596.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/07/10/207596.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/207596.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/207596.html</trackback:ping><description><![CDATA[<div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #0000FF; ">&lt;!</span><span style="color: #FF00FF; ">DOCTYPE&nbsp;html</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">html</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">我们希望做到的是<br />
</span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.当点击某个链接，我们3希望能留在这个网页而不是转到另外一个窗口<br />
</span><span style="color: #008080; ">&nbsp;5</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.当点击某个链接，我们希望能在这个网页上同事看到那张图片和原有的图片清单<br />
</span><span style="color: #008080; ">&nbsp;6</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">--&gt;</span><br />
<span style="color: #008080; ">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">&lt;!--</span><span style="color: #008000; "><br />
</span><span style="color: #008080; ">&nbsp;8</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.当我们触发onclick事件时，不仅showPic函数会被调用，链接也会起作用，而跳转到另外一个窗口<br />
</span><span style="color: #008080; ">&nbsp;9</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所以，这里有个知识点，对于a标签的onclick函数，如果你让onclick函数返回false，那么浏览器<br />
</span><span style="color: #008080; ">10</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;会认为你没有点击链接，也就不会发生跳转。<br />
</span><span style="color: #008080; ">11</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.如果吧a标签看成对象，你会发现这个很容易理解,我们给a标签增加了onclick函数具体的做什么事情，<br />
</span><span style="color: #008080; ">12</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;也就是说onclick函数是a对象里的一个方法，那么这里的this就是指的就是a标签这个对象。现在你明白<br />
</span><span style="color: #008080; ">13</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为什么要用this了吧（想想C++、java）<br />
</span><span style="color: #008080; ">14</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">--&gt;</span><br />
<span style="color: #008080; ">15</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">head</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">16</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">meta&nbsp;</span><span style="color: #FF0000; ">charset</span><span style="color: #0000FF; ">="utf-8"</span><span style="color: #FF0000; ">&nbsp;</span><span style="color: #0000FF; ">/&gt;</span><br />
<span style="color: #008080; ">17</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">title</span><span style="color: #0000FF; ">&gt;</span>Image&nbsp;Gallery<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">title</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">head</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">19</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">body</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">20</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">h1</span><span style="color: #0000FF; ">&gt;</span>Snapshots<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">h1</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">ul</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">22</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;&lt;</span><span style="color: #800000; ">a&nbsp;</span><span style="color: #FF0000; ">href</span><span style="color: #0000FF; ">="images/fireworks.jpg"</span><span style="color: #FF0000; ">&nbsp;title</span><span style="color: #0000FF; ">="A&nbsp;fireworks&nbsp;display"</span><span style="color: #FF0000; ">&nbsp;onclick</span><span style="color: #0000FF; ">="return&nbsp;showPic(this);"</span><span style="color: #0000FF; ">&gt;</span>Fireworks<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">a</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;&lt;</span><span style="color: #800000; ">a&nbsp;</span><span style="color: #FF0000; ">href</span><span style="color: #0000FF; ">="images/coffee.jpg"</span><span style="color: #FF0000; ">&nbsp;title</span><span style="color: #0000FF; ">="A&nbsp;cup&nbsp;of&nbsp;black&nbsp;coffee"</span><span style="color: #FF0000; ">&nbsp;&nbsp;onclick</span><span style="color: #0000FF; ">="return&nbsp;showPic(this);"</span><span style="color: #0000FF; ">&gt;</span>Coffee<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">a</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">24</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;&lt;</span><span style="color: #800000; ">a&nbsp;</span><span style="color: #FF0000; ">href</span><span style="color: #0000FF; ">="images/rose.jpg"</span><span style="color: #FF0000; ">&nbsp;title</span><span style="color: #0000FF; ">="A&nbsp;red.&nbsp;red&nbsp;rose"</span><span style="color: #FF0000; ">&nbsp;onclick</span><span style="color: #0000FF; ">="return&nbsp;showPic(this);"</span><span style="color: #0000FF; ">&gt;</span>Rose<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">a</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">25</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;&lt;</span><span style="color: #800000; ">a&nbsp;</span><span style="color: #FF0000; ">href</span><span style="color: #0000FF; ">="images/bigben.jpg"</span><span style="color: #FF0000; ">&nbsp;title</span><span style="color: #0000FF; ">="The&nbsp;famous&nbsp;clock"</span><span style="color: #FF0000; ">&nbsp;onclick</span><span style="color: #0000FF; ">="return&nbsp;showPic(this);"</span><span style="color: #0000FF; ">&gt;</span>Big&nbsp;Ben<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">a</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">li</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">26</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">ul</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">27</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">img&nbsp;</span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="placeholder"</span><span style="color: #FF0000; ">&nbsp;src</span><span style="color: #0000FF; ">="images/placeholder.jpg"</span><span style="color: #FF0000; ">&nbsp;alt</span><span style="color: #0000FF; ">="my&nbsp;image&nbsp;gallery"</span><span style="color: #FF0000; ">&nbsp;</span><span style="color: #0000FF; ">/&gt;</span><br />
<span style="color: #008080; ">28</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">p&nbsp;</span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="desp"</span><span style="color: #0000FF; ">&gt;</span>Choose&nbsp;an&nbsp;Image<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">p</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">29</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">script&nbsp;</span><span style="color: #FF0000; ">type</span><span style="color: #0000FF; ">="text/javascript"</span><span style="color: #FF0000; ">&nbsp;src</span><span style="color: #0000FF; ">="scripts/showPic.js"</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">script</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">30</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">body</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #008080; ">31</span>&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">html</span><span style="color: #0000FF; ">&gt;<br />
</span></div><br />showPic.js<br /><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><br /><span style="color: #0000FF; ">function</span>&nbsp;showPic(whichPic)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;source&nbsp;=&nbsp;whichPic.getAttribute("href");<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;placeholder&nbsp;=&nbsp;document.getElementById("placeholder");<br />&nbsp;&nbsp;&nbsp;&nbsp;placeholder.setAttribute("src",source);<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;text&nbsp;=&nbsp;whichPic.getAttribute("title");<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;txtNode&nbsp;=&nbsp;document.getElementById("desp").firstChild;<br />&nbsp;&nbsp;&nbsp;&nbsp;txtNode.nodeValue&nbsp;=&nbsp;text;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">false</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">/*</span><span style="color: #008000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;经验总结:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.由于js是动态语言，所以存在一个很严重的问题，<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那就是你自己取的变量名称时，尽可能的采用骆驼峰写法，<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;并且最后借助好的编辑器，有自动补全功能的编辑器，一面<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;拼写错误，这种错误低级，而且查找起来十分困难。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.如果站点用到多个js文件，因该把它合并到一个文件中。以减少请求次数，提高性能。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">*/</span><br />}</div><img src ="http://www.cppblog.com/sixleaves/aggbug/207596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-07-10 02:53 <a href="http://www.cppblog.com/sixleaves/archive/2014/07/10/207596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JS(02)-DOM介绍</title><link>http://www.cppblog.com/sixleaves/archive/2014/07/09/207583.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 08 Jul 2014 19:33:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/07/09/207583.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/207583.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/07/09/207583.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/207583.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/207583.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/sixleaves/archive/2014/07/09/207583.html'>阅读全文</a><img src ="http://www.cppblog.com/sixleaves/aggbug/207583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-07-09 03:33 <a href="http://www.cppblog.com/sixleaves/archive/2014/07/09/207583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JS(01)-JavaScript语法</title><link>http://www.cppblog.com/sixleaves/archive/2014/07/09/207582.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 08 Jul 2014 16:42:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/07/09/207582.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/207582.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/07/09/207582.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/207582.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/207582.html</trackback:ping><description><![CDATA[<span style="font-size: 12pt;">准备工作：</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; 编写javascript并不需要复杂的工具，其编写的代码必须通过HTML/XHTML文档执行。有两种方式可以做到，第一种是在head标签中的script标签中写生javascript代码。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; 另外一种方式使我们推荐的使用的方式，</span><span style="color: #008000; font-size: 12pt;">把js代码放在外部，在引用进去，引用的位置最好是在HTML文档最后，&lt;/body&gt;之前，这样可以加快浏览器加载页面的速度。引</span><br /><span style="color: #008000; font-size: 12pt;">
&nbsp; &nbsp; &nbsp; 用的方式就是在script标签中的src属性上赋值，所写js代码的路径。</span><br />
<span style="font-size: 12pt; color: #008080;">&nbsp; 1</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;</span><span style="background-color: #eeeeee; font-size: 12pt;">&lt;!</span><span style="background-color: #eeeeee; font-size: 12pt;">DOCTYPE&nbsp;HTML</span><span style="background-color: #eeeeee; font-size: 12pt;">&gt;<br />
</span>
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #008080; font-size: 12pt;">&nbsp;2</span><span style="font-size: 12pt;">&nbsp;&lt;html&gt;</span></div>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><span style="color: #008080; font-size: 12pt;">&nbsp;3</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&lt;head&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;4</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;charset="utf-8"&nbsp;/&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;5</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;&lt;/title&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;6</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&lt;/head&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;7</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&lt;body&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif" alt="" /><span style="font-size: 12pt;">..</span><br />
<span style="color: #008080; font-size: 12pt;">&nbsp;9</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;script&nbsp;src="file.js"&gt;&lt;/script&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">10</span><span style="font-size: 12pt;">&nbsp;&nbsp;&nbsp;&lt;/body&gt;</span><br />
<span style="color: #008080; font-size: 12pt;">11</span><span style="font-size: 12pt;">&nbsp;&lt;/html&gt;</span></div><span style="font-size: 12pt;">
语法：</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">一.语句</span><span style="font-size: 12pt;">：js的语句可以不加分号而把他们放在不同行上，但这不是好的编程习惯，为了培养好的编程习惯，我们每条语句都给它加上分号，不管是不同行的还是同一行的。</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">二.注释</span><span style="font-size: 12pt;">：（1）行注释// (2)段注释/**/ (3)HTML风格行注释&lt;!--(不推荐使用，容易于HTML注释混淆)</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">三.变量</span><span style="font-size: 12pt;">：使用var进行声明，由于js是动态语言，可以直接用变量赋值代替变量声明（test = &#8220;fuck&#8221;，将自动声明test变量）。但是为了培养编程习惯，请在使用前声明。</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">四.变量类型：</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;（1）字符串：包含在单引号或者双引号里的字符序列，选择的</span><span style="color: #008000; font-size: 12pt;">简单原则是：如果字符串包含单引号，则使用双引号，如果字符串包含双引号，则是同单引号</span><span style="font-size: 12pt;">。如：var mood = "don't ask";淡然也可以用转义字符,那么你仍然可以使用单引号，var mood &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 'don\'t ask';</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (2) 数值：可以直接使用整数，浮点数。var a = 3, b= 2.32;</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (3) 布尔值:var test=true,sleeping = false;注意布尔值true于字符串"true"是两码事</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-size: 12pt;">Tips:标量--如果某个数是标量（scalar），它在任意时刻只能有一个值。（1）-（3）都是标量。</span><br />
<br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (4) 数组:相对于标量，如果想用变量存储一组值，就得用数组。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.1创建数组：</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 使用数组有两种方式：一种是先声明数组，在对数字赋值。一种是在声明是就赋值。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 第一种的话，如果使用整数索引，0开始表示第一个。第二种方式，是var test = Array("waht",1,"fuck","come",1.23);//创建了有五个元素的数组</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tips:数组的元素还可以是数组。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.2关联数组：（哈希数组）</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var test = array();test["first"] = 1</span><span style="color: #008000; font-size: 12pt;">;//不推荐使用关联数组，因为在js中，每中类型其实都是实例对象，所以这种方法的本质是给Array()对象添加</span><br /><span style="color: #008000; font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 属性，如上，添加就是first属性。最好的情况下不应该修改Array对象属性，而是使用OBject对象。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; （5）对象：</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 与数组一样的是，对象也是使用一个名字表示一组值。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5.1:创建对象，使用Object关键字。如：var lesson = Object();</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5.2:使用.号了添加或者获取对象的属性。如 lesson.name = "John";</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5.3:</span><span style="color: #008000; font-size: 12pt;">创建对象的另外一种简单方法----花括号方法:</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var lesson = {name:"John",year:1945};</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Tips:</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var beatles = {};//创建一个Object对象</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;beatles.vocalist = lesson;//为Object对象添加vocalist属性，值为lesson对象。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;于是我们这样获取值beatles.vacalist.name,beatles.vacalist.year</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">五.操作</span><span style="font-size: 12pt;">： &nbsp;（1）算数操作运算符（+ - * / ）</span><span style="color: #008000; font-size: 12pt;">(2)字符串拼接运算符（+）</span><span style="font-size: 12pt;">。</span><span style="color: #008000; font-size: 12pt;">so：10 + 20 ---30;"10" + 20 --- 1020;</span><span style="font-size: 12pt;">(3)另外一个特殊的很好用的是+=，如：var year=2000;var message = "this is "; message += year;---"This is 2000";</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">六.</span><span style="font-size: 12pt;"> 条件语句、循环语句、函数（函数有点区别）:略（于C、C++、Java差不多）</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">七.变量的作用域:</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 全局变量:可以在脚本任何位置引用。</span><br /><span style="font-size: 12pt;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 局部变量：存在于指定函数内部。在函数内部，</span><span style="color: #008000; font-size: 12pt;">使用var关键字的变量一定是局部变量，而没有使用的这是全局变量。</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size: 12pt; color: #0000ff;">function</span><span style="background-color: #eeeeee; font-size: 12pt;">&nbsp;square(num)&nbsp;{</span>
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total&nbsp;=&nbsp;num&nbsp;*&nbsp;num;</span><span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">total为全局</span><span style="color: #008000; "><br />
</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff; font-size: 12pt;">return</span><span style="font-size: 12pt;">&nbsp;total;</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<br />
<span style="color: #0000ff; font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var</span><span style="font-size: 12pt;">&nbsp;total&nbsp;=&nbsp;50;</span><br />
<span style="color: #0000ff; font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var</span><span style="font-size: 12pt;">&nbsp;number&nbsp;=&nbsp;square(20);</span><span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">改变total，因为其实全局的。</span><span style="color: #008000; "><br />
</span><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(total);</span><span style="color: #008000; font-size: 12pt;">//</span><span style="color: #008000; font-size: 12pt;">400</span></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size: 12pt; color: #0000ff;">function</span><span style="background-color: #eeeeee; font-size: 12pt;">&nbsp;square(num)&nbsp;{</span>
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var total = num * num;//改成这样就安全了</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return total;</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 12pt; color: #ff0000;">八:对象</span><span style="font-size: 12pt;">：一个对象包含属性和方法，都可以通过.来访问属性和方法。</span><br /><span style="font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 内建对象（其实应该成为类）：Array().可以使用new关键字来创建var beatles = new Array();还有Date类、Math类。</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000; font-size: 12pt;">&nbsp; 宿主对象():也即是JS寄生的环境，如浏览器环境，则此时有浏览器提供的对象被成为宿主对象，Form、IMage、Element、document<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /></span><span style="color: #ff0000; font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ff0000; font-size: 12pt;">总结:</span><span style="color: #ff00ff; font-size: 12pt;">JS对对象的定义有点奇葩，这里总结下，首先同意观点，可以把它所说的对象看成类，而实例化对象的方法有两种，一种是使用关键字如Array()、Object()等即可，一种是<br /></span><span style="color: #ff00ff; font-size: 12pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 最通用的显示的使用new关键字，进行对象的创建如new Array()等。</span><span style="color: #0000ff; font-size: 12pt;"> </span><span style="color: #0000ff; font-size: 12pt;"></span><img src ="http://www.cppblog.com/sixleaves/aggbug/207582.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-07-09 00:42 <a href="http://www.cppblog.com/sixleaves/archive/2014/07/09/207582.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(SQL总结精华)sixleaves之mysql之表的连接详细总结</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/24/206703.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Thu, 24 Apr 2014 12:52:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/24/206703.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206703.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/24/206703.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206703.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206703.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/sixleaves/archive/2014/04/24/206703.html'>阅读全文</a><img src ="http://www.cppblog.com/sixleaves/aggbug/206703.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-24 20:52 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/24/206703.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql左连接、右连接、内连接。</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/23/206691.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Wed, 23 Apr 2014 15:46:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/23/206691.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206691.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/23/206691.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206691.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206691.html</trackback:ping><description><![CDATA[再讲连接之前，假设你们已经知道了全相乘的概念，不懂的化得先去补补这点数学知识。<br />20%：<br />1.所谓左连接，其实就是左表不懂，用条件去匹配右表，为true时把右表相应的行并到左表，false时在其上填上NULL。语法规则就是 Atb left join Btb ON conditions;这句话其实可以直接把它当作就是一张表对待。而所谓的右连接只是相对于左连接而言，两个其实是等价的，Atb left join Btb ON conditions;~Btb right join Atb ON conditions，所以你只要记住左连接，再记住右连接是相对于左连接，其实是等价的就够了。<br /><br />2.所谓的内连接，其实就是左右连接的交集，内连接不会把没匹配的行加入结果集中，但是左右连接会，并且他们会为其填上NULL。语法格式是Atb inner join Btb On conditions<br /><br />3.如果说左连接时，左表有几条数据那么，连接后的表的数据条数和左表一样。对吗？这是一个错误的概念，因为结果集的条数是左右两个表共同决定的，如果右表中对于左表有两条符合的记录，那么在结果集中对应也有两条，而不是一条。<br /><br />4.左右连接和内连接相对于全相乘效率上当然是高了很多，这是因为一般而言它们用到了索引。<img src ="http://www.cppblog.com/sixleaves/aggbug/206691.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-23 23:46 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/23/206691.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql之where型、from型、exists型子查询</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/23/206690.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Wed, 23 Apr 2014 15:36:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/23/206690.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206690.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/23/206690.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206690.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206690.html</trackback:ping><description><![CDATA[where型：在mysql中这三种子查询EXISTS型比较特殊，前两种都是很基础滴，where型字查询一般会结合in来使用，in(sql),in里面的东西相当于一个集合。<br /><br />from型：<br />from型主要是为了把某次查询结果当作查询表再查询。一般书写规则是（sql） as tmp,这里sql是指某次查询结果，tmp是其别名。<br /><br />EXISTS型：<br />EXISTS子查询，就是用外层的sql作为内层sql的条件，如果条件为真那么输出外层sql。讲的有点抽象，我会再分别整理补充完整这三种子查询的各个典型例子。<img src ="http://www.cppblog.com/sixleaves/aggbug/206690.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-23 23:36 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/23/206690.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql Order by 与limit</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/23/206689.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Wed, 23 Apr 2014 15:24:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/23/206689.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206689.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/23/206689.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206689.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206689.html</trackback:ping><description><![CDATA[知识点一：在mysql中order by就是用来排序的，排序分为两种，一种是升序，一种是降序，升序就是ASC，而降序是DESC。Order By是对最终结果集进行排序所以它必须是在where/group by/having之后才有意义。<br />情景一：假设有要排序的两个字段，先按照字段a进行升序，再按照字段b进行升序，那么可以写成order by a asc,b asc;<br /><br />知识点二：order by还可以和limit结合起来使用，达到取某几个值的目的，如取第四名到，第六名的值，就是order by desc limit 3,3;即可，至于这两个参数，第一个其实就是C语言数组中的索引，也是从零开始计数，所以第四名也就是第四个是3，而第二个参数就是从第四名到第六名的个数，6-4+1=3，所以当然是3啦~。<br /><br />知识点三：如果继续完善上次的模型，order by是放在最终结果集之后，而limit是作用于order by长生的结果集，所以可以认为，limit长生的结果集是sql查询中最顶层的结果集。<br /><img src ="http://www.cppblog.com/sixleaves/aggbug/206689.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-23 23:24 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/23/206689.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql之sql查询分析建模对应的group by与having</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/22/206682.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 22 Apr 2014 14:30:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/22/206682.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206682.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/22/206682.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206682.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206682.html</trackback:ping><description><![CDATA[这篇随笔，我认为是sql查询中不出错十分重要的一篇，我们都知道在100%的知识中只有20%的是最重要也就是核心的东西，这里我觉得这就是这20%。不多说直接进入正题。我们代开mysql，可以用cmd运行其命令行客户端程序，连接进mysql，我们做如下实验。<br />首先我们要明白，在数据库服务器一般都是24小时运行滴，其数据与其说是存在硬盘上，但很大部分为了提高查询效率，坑定得放在内存中，而我们用sql语句进行查询时的第一次查询出来的结果集是where作用于内存中这张表的结果。（Understand？）。如下图<br /><img src="http://www.cppblog.com/images/cppblog_com/sixleaves/sql-where.png" width="1298" height="600" alt="" /><br />这个我们暂且把它称为结果集1(result1),接着就是聚集函数（max、sum、min、count、avg）和group by还有各个列的计算结果作用于result1长生result2，图类似，不再画了。一般聚集函数是配合group by使用才比较有意义。这里还提到了计算结果这一动作，其实说白了，可以把每一个字段看成变量，各个变量在一起计算的过程。这个字段即可用在where、having、group by之后，也可用在select上，但是我们应该注意的是如果你这样操作如下：<br /><br />select a,(c -d) as dis from st where dis &lt; 60 group by a;这是错误，想想为什么，where子句作用于result0长生result1，也就是dis是属于result1的，但是where无法作用与result1，如果要再次筛选可以用having，它就相当于第二次的where。这就是我介绍这个模型帮助理解sql语句的重要性，同时也是你理解sql的重要知识。这个相信很多所谓的大学老师是不会讲滴。<br /><br />接着having字句作用与result2长生result3，图和上图一样，你可以自己画出完整的图有利于加深理解。<br /><br />这里再提一个十分重要的概念，上面有提过，就是列看成变量。这十分重要， 这样你可像写C语言一样思考如何写出简洁有效率合适的sql语句（结合刚才那个模型），如有张表st，有score字段，该字段记录学生成绩，如果用统计不及格人数你可以这样做select sum(score &lt; 60) as num from st;这里其实运算score &lt; 60 和sum都是作用于result2.重要的是score &lt; 60比较出来的是布尔值 1 或者0也就是真或者假，这个是很好利用的一点。<br />以上这两个例子有助于更深的理解和记忆这个模型，而该模型反过来有助于你sql对语句的理解。<img src ="http://www.cppblog.com/sixleaves/aggbug/206682.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-22 22:30 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/22/206682.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之alter对已建立表的修改详细语法</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/22/206680.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 22 Apr 2014 08:01:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/22/206680.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206680.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/22/206680.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206680.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206680.html</trackback:ping><description><![CDATA[alter有修改意思，其主要动作有增加，删除，修改类型，改变列名。对应的英文单词就是add、drop、modify、change<br /><br />增加st表：<br />alter table st add colname type...<br /><br />修改st表：<br />alter table st modify colname type...<br /><br />删除st表指定列<br />alter table st drop colname;<br /><br />更改st表指定列<br />alter table st change colOldName colNewName type...<br /><br />自己找数据库练习上10篇即可。<br /><br /><img src ="http://www.cppblog.com/sixleaves/aggbug/206680.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-22 16:01 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/22/206680.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql时间日期类型</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/22/206679.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 22 Apr 2014 07:52:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/22/206679.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206679.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/22/206679.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206679.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206679.html</trackback:ping><description><![CDATA[mysql时间日期类型我们主要学习4大种。<br /><br />date、time、datetime、year<br />date 表示的范围是1000 01 01 - 9999 12 31<br />time 表示的范围是-838：59：59 &nbsp;- 839：59：59<br />datetime表示范围就是两者的组合<br />year的表示范围是以1901为基准，其只用一个字节表示，一共有255中变化，所以可表示到2155年。<br /><br />还有一种比较特殊的类型是timestamp，它会自动填入日期和时间，值为当前计算机的日期时间值。如创建一张表<br />create table test(<br />&nbsp; &nbsp;mytime timestamp default CURRENT_TIMESTAMP,<br />&nbsp; &nbsp;id int<br />);<br />然后插入两条数据看看，insert into test (id) values(1),(2);<br />再select &nbsp;* from test；就能看到timestamp的作用了。<img src ="http://www.cppblog.com/sixleaves/aggbug/206679.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-22 15:52 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/22/206679.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql三大数据类型之int类型</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/22/206598.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 22 Apr 2014 07:12:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/22/206598.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206598.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/22/206598.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206598.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206598.html</trackback:ping><description><![CDATA[前沿：<br />计算机专业的童鞋应该都知道，补码的知识，在这里我们简要复习一下。<br />在计算机中我们用二进制表示数字，假设是一个字节，则它有8位<br />对于正整数表示范围为：<br />0000 0000 - 0111 1111<br />最高位表示符号位，0表示整数<br /><br />对于负数可能你回认为就是<br />1000 0000 -1111 1111<br />表示-0 到 -127<br />但是这个就和正整数有了重复即-0等于0。而从0到 -127一共有128中变化，0已经重复，那么我们要做的就是消除重复，多表示一种，也就是多表示-128这种变化<br />那么如何表示呢。我们发现当他们减去-128时刚好为-1 到 -128，所以负数的补码要转换成正常的整数就是减去2 ^ N N为其位数<img src ="http://www.cppblog.com/sixleaves/aggbug/206598.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-22 15:12 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/22/206598.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql浮点类型和字符类型</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/22/206677.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 22 Apr 2014 07:11:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/22/206677.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206677.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/22/206677.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206677.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206677.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/sixleaves/archive/2014/04/22/206677.html'>阅读全文</a><img src ="http://www.cppblog.com/sixleaves/aggbug/206677.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-22 15:11 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/22/206677.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之Mysql结合php之核心sql语句</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/14/206581.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Mon, 14 Apr 2014 07:01:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/14/206581.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206581.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/14/206581.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206581.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206581.html</trackback:ping><description><![CDATA[1.增<br />2.删<br />3.改<br />4.查<img src ="http://www.cppblog.com/sixleaves/aggbug/206581.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-14 15:01 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/14/206581.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之mysql基本入门语句</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/14/206580.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Mon, 14 Apr 2014 06:56:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/14/206580.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206580.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/14/206580.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206580.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206580.html</trackback:ping><description><![CDATA[入门mysql其实十分简单。<br />如下：<br />我们要解决的问题是怎么连接数据库（需要的接口，和各种相应参数是什么），怎么选中对应的库来使用（于是有了怎么查看库，删除库，创建库的问题），选中库后怎么查看对应表（于是有了删除表，清空表的问题，创建表的问题）。<br />1.首先在windows中我们在cmd下来连接mysql作为对数据库的一些基本联系，连接数据库的命令为mysql -u用户名 -p密码，我的root用户密码为111111，所以连接语句为mysql -uroot -p111111。<br />2.接着是怎么选中库，在这之前你可以查看相应的库SHOW DATABASES;然后选中库用USE，假设我选中mydb库，语法就是USE mydb;对应的删除库为DROP DATABASE mydb；<br />3.是查看表SHOW TABLES查看所有表，查看指定表详细内容用SELECT语句，最基本的为SELECT * FROM shop;输出shop表内容。删除表为DROP TABLE shop，<br />清空表为truncate tablename，如truncate shop就清空了shop表，改表名，即rename table tablename to newtablename。如果决定全部清空，truncate比delete更快些。<img src ="http://www.cppblog.com/sixleaves/aggbug/206580.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-14 14:56 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/14/206580.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sixleaves之Mysql安装篇（精简记录）</title><link>http://www.cppblog.com/sixleaves/archive/2014/04/14/206579.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Mon, 14 Apr 2014 06:24:00 GMT</pubDate><guid>http://www.cppblog.com/sixleaves/archive/2014/04/14/206579.html</guid><wfw:comment>http://www.cppblog.com/sixleaves/comments/206579.html</wfw:comment><comments>http://www.cppblog.com/sixleaves/archive/2014/04/14/206579.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sixleaves/comments/commentRss/206579.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sixleaves/services/trackbacks/206579.html</trackback:ping><description><![CDATA[我们学习php，最佳的组合就是php+mysql+Linux、php重在学习结合java学习实现各种框架和程序思想、mysql重在学习更重数据库的优化和sql语句的编写、Linux学习也需要结合mysql来使用、实现数据库的高并发等、和各种优化，而更深入就要涉及内核、在内核之前、我们必须掌握使用mysql和php开发下在linux中常用更种命令等等。好了说了这么多前沿、下面我们准备mysql入门，个人能力有限，有错误还望指教。<br />On Windows：<br />第一步是去下载php、mysql、apache软件，mysql软件可以去官网下、如果觉得下载速度慢，用专用的下载工具，开个会员什么滴，下载还是很快滴、下载要注意的事项是，如果你下载的是apache2 or apache1对应下载php软件必须是下载VC6编译版本的，将会被淘汰，如果是xp系统就装这个吧，如果是win7及之后系统，建议到这里下载<span style="font-size: 12px;">http://www.apachelounge.com/，选择对应版本的vc11的话，php也要是vc11版本的，建议选择vc11版本。<br />第二步，安装mysql、安装mysql在window下很简单，有几个要注意的是，我们一般在安装时候自己配置安装环境，在安装时第一先选择软件安装的位置，第二部选择（mysql server datafiles）mysql数据库数据文件存放的位置，第三要记得选择数据库默认的编码为utf8，这样有较好的兼容性。<br />第三步，注意选择时选择开发者模式还是服务器模式几乎没什么差别，无非是内存占用的多少，在选择数据库类型时，有三个选项，分别是包含事务型，一种是只支持事务，一种是不支持事务型，我们一般选择第一个。接着还有一个数据存放位置，这个与刚才那个不同，这个数据专门指定了事务型数据存放的位置，这种数据对应的表叫做innoDB表。</span><img src ="http://www.cppblog.com/sixleaves/aggbug/206579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sixleaves/" target="_blank">swp</a> 2014-04-14 14:24 <a href="http://www.cppblog.com/sixleaves/archive/2014/04/14/206579.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>