答案:请看下面用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秒
documents.cookie = "Cookie1=测试数据;expires="+ Then.toGMTString()
}
function Get(){
var cookieString = new String(documents.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>
上一个:在网页中实现OICQ里的头像选择的下拉框 (附例子)
下一个:请看被打开的子窗口继承父窗口定义的styleSheets的例子