请看用javascript设置和读取cookie的简单例子

来源:互联网 发布:python入门书籍 知乎 编辑:程序博客网 时间:2024/05/01 23:48
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
请看下面用javascript设置读取cookie简单例子,现在的问题是,如果要设置的是一个cookie集,比如在cookie1集中有uname,uid两组信息,应该如何写呢?
cookie("cookie1")("uname")="testuser"
cookie("cookie1")("uname")="testuid"

------------------------------------------------------------------------
<html>
<body>
设置读取 cookies...<br>
<input type = button value = "设置cookie" onclick = "set()">
<input type = button value = "读取cookie" onclick = "get()"><br>
<input type = text name = textbox>
</body>


<script language="javascript">
function set(){
var then = new date()
then.settime(then.gettime() + 60*1000 ) //60秒
document.cookie = "cookie1=测试数据;expires="+ then.togmtstring()
}

function get(){
var cookiestring = new string(document.cookie)
var cookieheader = "cookie1="
var beginposition = cookiestring.indexof(cookieheader)
if (beginposition != -1){
document.all.textbox.value = cookiestring.substring(beginposition
+ cookieheader.length)
}
else
document.all.textbox.value = "cookie 未找到!"
}
</script>
</html>
<<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击