asp中利用setcookie和getcookie传值

来源:互联网 发布:js事件绑定和事件委托 编辑:程序博客网 时间:2024/06/05 14:45

post.asp页面

<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title>    <script type="text/javascript">     function SetCookie(name,value)       {          document.cookie=name+"="+escape(value);          path="/" ;        }   </script></head><body>        <a href="read.asp" id="1" onClick="SetCookie('aid',this.id)">1</a><br /><br />         </body></html>


read.asp页面

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title>    <script type="text/javascript">      function GetCookie(name)      {       var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"))                if(arr != null) return unescape(arr[2]);       else return null;      }           alert(GetCookie('aid'));  window.onload=function(){ document.getElementById("test").value=GetCookie('aid');}        </script>    </head><body><label>    <form name="form1" method="post" action="" id="form1"><input type="text" name="textfield"  id="test" value=""/>         </form>   </label></body></html>


是通过id传值,缺点是缓存不能及时清除。

0 0
原创粉丝点击