c# cookie的使用,以及与javascript cookie的交互
C#:
创建:
HttpCookie cookie = new HttpCookie("regID");
cookie .Value = username;
cookie .Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
创建有子键的:
Response.Cookies["user"]["userName"] = Server.UrlEncode("大西瓜");//使用UrlEncode是为了使用javascript取出时不是乱码
或:
HttpCookie cookie=new HttpCookie("user");
cookie.Values["userName"] = "aaa"; //cookie.Values.Add("userName","aaa");
cookie .Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie) //Response.AppendCookie(cookie) ;
消除:直接删除没法删,因为COOKIE创建以后就保存在用户机器上了而不是在服务端
这样全部删除:
private HttpCookie cookie = null;
private string cookieName = string.Empty;
for (int i = 0; i < Request.Cookies.Count; i++)
{
cookieName = Request.Cookies[i].Name;
cookie = new HttpCookie(cookieName);
cookie .Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie );
}
删除子键:
HttpCookie cookie;
cookie = Request.Cookies["userInfo"]; &nbs
相关文档:
/************** javascript table操作类***************
* 仅适合IE6
****调用示例*****************************************
*
* var table=new TableOption("tb");
*
* var table=new TableOptions("tb",{hoverColor:#aabbcc,hover:false});
*
*****************************************************/
var $= ......
eval()函数
JavaScript有许多小窍门来使编程更加容易。
其中之一就是eval()函数,这个函数可以把一个字符串当作一个JavaScript表达式一样去执行它。
举个小例子:
var the_unevaled_answer = "2 + 3";
......
正则
<script>
function checkvalue(){
if(document.Form.content.value.replace(/\s/g,"")=="")
{
alert("内容不能为空!");
document.addForm.content.focus();
return false;
}
document.addForm.submit();
return ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace pub.mo
{
public class request
{
private request() { }
/// <summary>
/// 获取session
/// </summary>
/// <param name="_session_name" ......
在ie6中对于<input type="file"
/>通过obj.value是可以获取客户端选择文件的全路径的,但是到ie7就只能获取文件名,这对于onchange事件立即显示图片会有问题,可以用js方法解决
具体代码如下:
<html>
<head>
< ......