这个cookie该怎么实现?

CFree 2001-07-17 03:29:33
加精
在ASP页面中,我想在一个按钮被按下时,将一个文本框中的内容写到一个cookies中,请问该怎么实现?
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2001-07-17
  • 打赏
  • 举报
回复
简单的例子:
<script>
function test(){
document.cookie = "name="+document.form1.txt1.value
alert(document.cookie)
}
</script>
<form name=form1>
<input name=txt1>
<input type=button onclick="test()" value=测试>
</form>

创建cookie之后,最好用完后删除
孟子E章 2001-07-17
  • 打赏
  • 举报
回复
给你个例子:

<script>
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
// if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) {
// if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
function register(name) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie("TheCoolJavaScriptPage", name, expires)
}
</script>
<BODY><H1>Register Your Name with the Cookie-Meister</H1><P>
<SCRIPT>
var yourname = getCookie("TheCoolJavaScriptPage")
if (yourname != null)
document.write("<P>Welcome Back, ", yourname)
else
document.write("<P>You haven't been here in the last year...")
</SCRIPT>
<P> Enter your name. When you return to this page within a year, you will be greeted with a personalized greeting. <BR>
<FORM onSubmit="return false">
Enter your name: <INPUT TYPE="text" NAME="username" SIZE= 10><BR>
<INPUT TYPE="button" value="Register" onClick="register(this.form.username.value); history.go(0)">
</FORM>
iloveyouonlyonce 2001-07-17
  • 打赏
  • 举报
回复
我劝你不要用客户端写cookie的方法,
直接POST本页比较好。
response.cookies("yourname") = request.form("textname")
CFree 2001-07-17
  • 打赏
  • 举报
回复
net_lover(孟子E章):cookie的名字放在哪里?在别的页面中可以用request.cookies("cookiename")读吗?
孟子E章 2001-07-17
  • 打赏
  • 举报
回复
<input type=button onclick="document.cookie =document.formName.textName.value " value=按钮>
孟子E章 2001-07-17
  • 打赏
  • 举报
回复
document.cookie =document.formName.textName.value

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧