正则简单操作cookie、url search
正则操作cookie、url
- getCookie
function getCookie(key) {
var cookies = window.document.cookie,
reg = new RegExp('\\S*' + key + '=[^;]*', 'gi');
var result = cookies.match(reg);
return result && result[0].substr(0, key.length) === key ? result[0].substr(key.length + 1) : false;
}
- setCookie
function setCookie(key, value, expires) { // expires为天数
var date = new Date();
date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
document.cookie = key + '=' + value + ';expires=' + date;
}
- getQuery
function getQuery(key) {
var search = window.location.search,
reg = new RegExp('[^&]*' + key + '=[^&]*', 'gi');
var result = search.substr(1).match(reg);
return result && result[0].substr(0, key.length) === key ? window.decodeURIComponent(result[0].substr(key.length + 1)) : false;
}
- getUrl
function getUrl() {
var search = window.location.search,
reg = /[^=]+/g;
var deal = search.substr(1).split('&'),
result = {};
deal.forEach(function(item) {
var temp = item.match(reg);
temp && (result[temp[0]] = decodeURIComponent(temp[1]));
});
return result;
}
正则简单操作cookie、url search的更多相关文章
- js简单操作Cookie
贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
Visual Studio 2017中使用正则修改部分内容 最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效 ...
- Java服务端对Cookie的简单操作
Java服务端对Cookie的简单操作 时间 2016-04-07 10:39:44 极客头条 原文 http://www.cuiyongzhi.com/index.php/post/15.html ...
- Jquery操作cookie,实现简单的记住用户名的操作
一.jquery.cookie.js介绍 jquery.cookie.js是一个基于jquery的插件,一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cook ...
- jQuery中cookie的简单操作
jQuery 可以通过 jquery.cookie.js 插件来操作 Cookie. 用NuGet安装:PM>Install-Package js-cookie -Version 官网:http ...
- JavaScript 操作 Cookie
转自作者:聂微东出处:http://www.cnblogs.com/Darren_code/ 什么是 Cookie “cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器 ...
- Asp.net操作cookie大全
实例代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3 ...
- JS操作cookie以及本地存储(sessionStorage 和 localStorage )
JS操作cookie cookie的操作用两种方式 1.substring //创建cookie function setCookie(name,value,expires,path,domain,s ...
- Cookie介绍及JavaScript操作Cookie方法详解
本文主要为大家简单介绍了以下Cookie的用途.运行机制,以及JavaScript操作Cookie的各种方法,总结的比较全面,希望能给大家带来帮助. 什么是 Cookie “cookie 是存储于访问 ...
随机推荐
- 后台管理系统好用的UI框架
https://www.layui.com/demo/form.html
- salt+jenkins+gitlab+ecs构建公司部署平台
1.网络架构图如下 2.采用这种方案的原因 1.现网机器都在各个省机房内网,或者堡垒机内部.无法直接从公司总部ssh到各个现网机器 2.现网机器可以访问到公网.因此可以从公网下载制作的tar包 3.每 ...
- TypeScript 学习资料
TypeScript 学习资料: 学习资料 网址 TypeScript Handbook(中文版)(推荐) https://m.runoob.com/manual/gitbook/TypeScript ...
- mysql用户管理及授权
以mariadb5.5版本为例 新建用户 登录mariadb # mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Com ...
- ningx.conf location
server { listen ; server_name localhost; location /dirName { alias "C:/Users/VALEB/Downloads/in ...
- 信号监测---verilog
信号监测---verilog 此模块用于监测某一信号源是否持续稳定的传送. 监测思路:监测信号源高电平或者低电平的宽度是否始终保持一致(一定范围内允许有误差) `timescale 1ns / 1ps ...
- django ORM多对多操作
创建多对多: 方式一:自定义关系表 class Host(models.Model): nid = models.AutoField(primary_key=True) hostname = mode ...
- [例子] nginx负载均衡搭建及测试
一.Nginx + Tomcat 负载均衡测试(负载均衡+部分静态图片处理) 环境说明: nginx+tomcat @ubuntu ok 首先你得有一个Ubuntu或者什么其他的linux. 安装j ...
- python简明教程代码
#!user/bin/env python #-*- coding:utf-8 -*- # code001 print('hello world') (only one quotation mark, ...
- python-pcl
python-pcl安装和使用 https://blog.csdn.net/joker_hapy/article/details/85006818 Ubuntu16.04下安装PCL及python-p ...