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

📄 day2_10.html

📁 JAVASCRIPT 高级编程
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    <td colspan="2">-<a href="../../1-teach/asp/index.html">ASP</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-teach/php/index.html">PHP</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-teach/java/index.htm">Java</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-teach/vb/index.htm">VB</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-teach/c/index.htm">C、C++</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-backend/database/php_mysql/index.html">PHP/MySQL</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2"><a href="../../1-backend/cgi_perl/perl_beginner/index.html">-Perl</a> 
    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2">-<a href="../../1-teach/other/index.htm">其它</a> </td>
  </tr>
  <tr> 
    <td colspan="2" bgcolor="#666699"> 
      <div align="center"><font color="#FFFFFF">更多教程</font></div>
    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" height="17"><a href="../../1hdml/index.html">-HDML</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" height="23"><font face="宋体"><a href="../../1-backend/database/course/day1_1.html">-网络数据库</a></font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" height="14"><a href="../../1-backend/protocols/ping/index.html"><font face="arial, helvetica, sans-serif">-ping</font></a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" height="20"><a href="../../1-backend/cgi_perl/search_engine/index.html">-创建搜索引擎</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" height="16">-<a href="../../1adobe/GoLive/index.html">Adobe GoLive</a></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2"><a href="../../1-backend/cgi_perl/templates/index.html">-模板</a></td>
  </tr>
  <tr bgcolor="#666699"> 
    <td colspan="2" align="center"><font color="#FFFFFF">合作伙伴</font></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" align="left">-<a href="http://www.5dmedia.com/" target="_blank">5D精英网</a></td>
  </tr>
  <tr align="center" bgcolor="#FFFFFF"> 
    <td colspan="2"> <img src="../../Library/front_monkey.gif" width="59" height="68"></td>
  </tr>
  </tbody> 
</table>
<!-- #EndLibraryItem --> </td>
 <!-- End of headlines (column 1: left column) --> <!-- Gutter between columns 1 and 2 --> 
 <td width="10" height="794"><img src="http://www.sohu.com/images/pixel.gif" width=10></td>
 <!-- Search box and directories (columns 2 and 3: middle columns, combined into one) --> 
 <td align=center valign=top width="558"> 
 <div align="left"><!-- #BeginEditable "1" --> 
<title>JavaScrip高级教程</title>
 <strong>第十页:复杂的cookies读取</strong> 
      <p>如果你想让你的cookie包含更多的信息,你可以将cookie的值<br>
        设得很长.假设我们要保存某人的姓名,年龄和电话号码:</p>
      <p>var the_cookie = &quot;username:thau/age:older than the hills/phone:411&quot;;<br>
        <br>
        document.cookie=&quot;my_happy_cookie=&quot; + escape(the_cookie);<br>
        <br>
        我用斜杠/来分割属性名称,用分号区别不同的属性名称及其<br>
        属性值.斜杠/和分号是不是绝对的选择,你可以使用任何的<br>
        字符做分割的标志:<br>
        <br>
        var the_cookie = &quot;username=thau&amp;age=older than the hills&amp;phone=<br>
        411&quot;;<br>
        <br>
        document.cookie=&quot;my_happy_cookie=&quot; + escape(the_cookie);<br>
        <br>
        你可以自行选择限位器.只要你注意在对cookie解码时也使用<br>
        同样的限位器即可.<br>
        <br>
        设置复杂的cookie时方法要复杂一些.我们建议你使用相关数<br>
        组来保存所有的信息,假设我们将该cookie保存到某人的硬<br>
        盘上:<br>
        <br>
        my_happy_cookie=username:thau/age:older than the hills/phone:411<br>
        <br>
        <br>
        你可以将这些信息放到一个方便的相关数组中:<br>
        <br>
        function readTheCookie(the_info)<br>
        <br>
        {<br>
        <br>
        &nbsp;&nbsp;&nbsp; // load the cookie into a variable and unescape it<br>
        <br>
        &nbsp;&nbsp;&nbsp; var the_cookie = document.cookie;<br>
        <br>
        &nbsp;&nbsp;&nbsp; var the_cookie = unescape(the_cookie);<br>
        <br>
        &nbsp;&nbsp;&nbsp; // separate the values from the cookie name<br>
        <br>
        &nbsp;&nbsp;&nbsp; var broken_cookie = the_cookie.split(&quot;=&quot;);<br>
        <br>
        &nbsp;&nbsp;&nbsp; var the_values = broken_cookie[1];<br>
        <br>
        &nbsp;&nbsp;&nbsp; // break each name:value pair into an array<br>
        <br>
        &nbsp;&nbsp;&nbsp; var separated_values = the_values.split(&quot;/&quot;);<br>
        <br>
        &nbsp;&nbsp;&nbsp; // loop through the list of name:values and load<br>
        &nbsp;&nbsp;&nbsp; // up the associate array<br>
        <br>
        &nbsp;&nbsp;&nbsp; var property_value = &quot;&quot;;<br>
        <br>
        &nbsp;&nbsp;&nbsp; for (loop = 0; loop <br>
        <br>
        <br>
        如果在你的JavaScript中有上面这段代码,你可以这样调用它:<br>
        <br>
        var cookie_information = new Array();<br>
        <br>
        readTheCookie(cookie_information);<br>
        <br>
        然后你就会正确设置了cookie_information[&quot;username&quot;],<br>
        cookie_information[&quot;age&quot;], 和cookie_information[&quot;phone&quot;].<br>
        <br>
        这些看起来可能有些难以理解,但实际上并不是很难.我们一<br>
        步步分析:<br>
        var the_cookie = document.cookie; <br>
        将cookie赋值给一个变量.<br>
        var the_cookie = unescape(the_cookie); <br>
        取消escape()的编码<br>
        var broken_cookie = the_cookie.split(&quot;=&quot;);<br>
        var the_values = broken_cookie[1]; <br>
        使the_values等同于username:thau/age:older than the hills/phone:411. <br>
        var separated_values = the_values.split(&quot;/&quot;); <br>
        生成一个包含3个元素名为separated_values的数组:<br>
        separated_values[0] = &quot;username:thau&quot;<br>
        separated_values[1] = &quot;age:older than the hills&quot;<br>
        separated_values[2] = &quot;phone:411&quot;<br>
        <br>
        for (loop = 0; loop <br>
        循环调用separated_values的3个元素.<br>
        property_value = separated_values[loop]; <br>
        提取当前的name:value配对,第1个配对是username:thau.<br>
        var broken_info = property_value.split(&quot;:&quot;); <br>
        将该配对分成名为broken_info的数组中的两个元素: <br>
        broken_info[0] = &quot;username&quot;<br>
        broken_info[1] = &quot;thau&quot;<br>
        <br>
        var the_property = broken_info[0]; <br>
        第1次经过这个循环是,the_property是&quot;username&quot; <br>
        var the_value = broken_info[1]; <br>
        其值是&quot;thau&quot; <br>
        the_info[the_property] = the_value; <br>
        这里开始发回相关数组的便捷功能.它使得the_info<br>
        [&quot;username&quot;] = &quot;thau&quot;,所以现在当你需要从cookie中查找<br>
        username时你只需:<br>
        var the_name = the_info[&quot;username&quot;];<br>
        <br>
        每次经过这个循环时,就在the_info中加入一个新元素.循<br>
        环到最后时, the_info[&quot;username&quot;] = &quot;thau&quot;, the_info<br>
        [&quot;age&quot;] = &quot;old as the hills&quot; ,而 the_info[&quot;phone&quot;] 
        = 411.<br>
        <br>
        有些烦琐,但是当你需要从cookie中输出入大量信息时这是一<br>
        个很好的办法.当然还有别的办法.<a href="day2_11.html">&gt;&gt;</a></p>
      <p><font face="宋体" size="3" color="#000000"><strong>JavaScript高级教程</strong></font><font color="#FF0000" face="宋体" size="3"><br>
        </font><font color="#FF0000">第一页</font> <a href="day2_1.html">Javascript高级教程-第2日</a><br>
        <font color="#FF0000">第二页</font> <a href="day2_2.html">神奇的字符串处理</a><br>
        <font color="#FF0000">第三页</font> <a href="day2_3.html">子字符串</a><br>
        <font color="#FF0000">第四页</font> <a href="day2_4.html">分割方法(splitting 
        method)</a><br>
        <font color="#FF0000">第五页</font> <a href="day2_5.html">相关数组</a><br>
        <font color="#FF0000">第六页</font> <a href="day2_6.html">相关数组的一个例子</a><br>
        <font color="#FF0000">第七页</font> <a href="day2_7.html">介绍cookie</a><br>
        <font color="#FF0000">第八页</font> <a href="day2_8.html">深入了解cookies</a><br>
        <font color="#FF0000">第九页</font> <a href="day2_9.html">读取cookies</a><br>
        <font color="#FF0000">第十页</font> 复杂的cookies读取<br>
        <font color="#FF0000">第十一页</font> <a href="day2_11.html">读取和编写多重cookies</a><br>
        <font color="#FF0000">第十二页</font> <a href="day2_12.html">再次深入了解cookies</a><br>
        <font color="#FF0000">第十三页</font> <a href="day2_13.html">cookie路径和域</a></p>
      <p><font size="3">[<a href="day1_1.html">第1课</a>][第2课][<a href="day3_1.html">第3课</a>][<a href="day4_1.html">第4课</a>][<a href="day5_1.html">第5课</a>]</font></p>
      <!-- #EndEditable --></div>
 </td>
 <!-- End of search box and directories (columns 2 and 3: middle columns, combined into one) --> 
 <!-- Gutter between columns 3 and 4 --> <!-- Other stuff (column 4: right column) --> 
 <!-- End of other stuff (column 4: right column) --> </tr>
 </table>
<!-- End of table surrounding page contents -->

 <hr noshade size=1 width=700>
 <span class=eng><br>
 Copyright (C) 1998-2000 Internet Technologies China.&nbsp; All rights reserved. 
 </span> 
</center>
</body>
<!-- #EndTemplate --></html>

⌨️ 快捷键说明

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