Cookie示例

时间:2021-04-24 01:51:08

//caozuocookie
        var webusername = "";
        function getCookie(name)
{
 var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
 if(arr=document.cookie.match(reg))
 
  return unescape(arr[2]);
 else
  return null;
}
if (getCookie("username")!=null) {
 String.prototype.trim = function() {
  return this.replace(/^(\s*)|(\s*)$/g,"");
var start = getCookie("username").indexOf("usernc=", start) + 7;
var end = getCookie("username").indexOf("&", start);
webusername =decodeURI(getCookie("username").substring(start, end));
$("#username").val(webusername);

}