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

📄 day2_12.html

📁 对javascript的简单介绍和讲解
💻 HTML
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312-80">
<style type="text/css">
<!--
a:link {  color: blue; text-decoration: none}
a:visited {  color: purple; text-decoration: none}
a:hover {  color: #CC0033; text-decoration: underline}
-->
</style>
<title>JavaScript高级教程</title>
</head>

<body topmargin="1" leftmargin="2">

<table border="0" width="591" cellspacing="0">
  <tr> 
    <td bgcolor="#ffff99" width="451">JavaScript高级教程 - 第二课</td>
  </tr>
  <tr> 
    <td bgcolor="#FF6600" width="451"><a href="mailto:thau@wired.com">Thau</a></td>
  </tr>
</table>
<div align="left">

  <table border="0" width="630" cellspacing="0">
    <tr> 
      <td width="458" valign="top" align="left" rowspan="2"><small><small><br>
        </small></small><strong>第十二页:再次深入了解cookies</strong>
        <p>现在你已经学会了如何设置和读取基本的cookie.然而基本<br>
          的cookie常常在用户关闭他的浏览器时会被自动删除.有时候<br>
          这样最好因为通常的域只允许在用户的机器上保留20个cookie.<br>
          但是如果你希望将cookie保存在用户的机器上你需要设置一<br>
          个cookie失效的时间,它的格式是一种叫做GMT的特殊格式.<br>
          例如:</p>
        <p>Mon, 27-Apr-1998 00:00:00 GMT<br>
          <br>
          要正确设置GMT不是一件容易的事,你需要计算好某个日期是星<br>
          期几.好在Javascript有一个日期的方法叫做toGMTString可以<br>
          帮助你.下面是设定远期的某个时间的一个例子:<br>
          var the_date = new Date(&quot;December 31, 2023&quot;);<br>
          <br>
          var the_cookie_date =the_date.toGMTString();<br>
          <br>
          一旦你设置了你的cookie的失效期,你在必须在cookie设置的<br>
          前面加入这条信息.因此你的cookie应该如下:<br>
          <br>
          cookie_name=blah_blah;expires=date<br>
          <br>
          通常你只需在cookie字符串中加入expires=date,然后用分号<br>
          分割不同的cookie.<br>
          <br>
          下面是一个如何建立有效期直至Mayan日历末尾的函数:<br>
          <br>
          <br>
          function<br>
          setCookie()<br>
          <br>
          {<br>
          <br>
          &nbsp;&nbsp;&nbsp; // get the information<br>
          <br>
          &nbsp;&nbsp;&nbsp; //<br>
          <br>
          &nbsp;&nbsp;&nbsp; var the_name = prompt(&quot;What's your name?&quot;,&quot;&quot;);<br>
          <br>
          &nbsp;&nbsp;&nbsp; var the_date = new Date(&quot;December 31, 2023&quot;);<br>
          <br>
          &nbsp;&nbsp;&nbsp; var the_cookie_date =the_date.toGMTString();<br>
          <br>
          &nbsp;&nbsp;&nbsp; // build and save the cookie<br>
          <br>
          &nbsp;&nbsp;&nbsp; //<br>
          <br>
          &nbsp;&nbsp;&nbsp; var the_cookie = &quot;my_cookie=&quot; + escape(the_name);<br>
          <br>
          &nbsp;&nbsp;&nbsp; the_cookie = the_cookie +&quot;;expires=&quot; + 
          the_cookie_date;<br>
          <br>
          &nbsp;&nbsp;&nbsp; document.cookie = the_cookie;<br>
          <br>
          }<br>
          <br>
          最后cookie应该如下所示:<br>
          <br>
          my_cookie=thau;expires=Fri,31-Dec-2023 00:00:00 GMT<br>
          <br>
          设置好cookie之后,它将在用户的机器中国存在直到失效期.<br>
          如果你将某个cookie的失效期设置得比当前时间还早,该cookie<br>
          实际上不能在用户的机器上存活.</p>
        <p>此外,还有两个只要的事项:路径(path)和域(domain)。<a href="day2_13.html"><font face="宋体" size="3">&gt;&gt;</font></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> <a href="day2_10.html">复杂的cookies读取</a><br>
          <font color="#FF0000">第十一页</font> <a href="day2_11.html">读取和编写多重cookies</a><br>
          <font color="#FF0000">第十二页</font> 再次深入了解cookies<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>
        <hr align="left">
        <!--webbot bot="Include" U-Include="../../copyright.html" TAG="BODY" startspan --> 
        <p><font face="verdana, arial, geneva, sans-serif" size="2"><a href="http://phtshop.yeah.net" target="_top">本文根据 
          网猴 相关文章改编,版权归原作者所有。</a> </font><font color="#000000"><span class="smallfont"></span></font></p>
        <!--webbot bot="Include" endspan i-checksum="15926" --> </td>
    </tr>
    <tr> </tr>
  </table>
</div>
</body>
</html>

⌨️ 快捷键说明

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