function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = (window.location.hash || window.location.search).substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}

  

调用:

getQueryString(参数)

  

更新:

const getUrlparam = (param) => {
const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
const r = window.location.search.substr(1).match(reg) || window.location.hash.substring((window.location.hash.search(/\?/)) + 1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
};

js正则获取url参数,包含hash[#]和search[?]两种通用的更多相关文章

  1. JS 正则 获取URL参数

    function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  2. js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq

    js_html_input中autocomplete="off"在chrom中失效的解决办法 分享网上的2种办法: 1-可以在不需要默认填写的input框中设置 autocompl ...

  3. 正则获取URL参数

    一 获取指定URL参数 function getUrlParams(name) { var reg = new RegExp("(^|&)" + name + " ...

  4. js正则获取url所带参数值

    在js字符串对象原型中添加这个获取链接参数值方法,getAddrVal(): String.prototype.getAddrVal = String.prototype.getAddrVal||fu ...

  5. 通过正则获取url参数

    1.通过正则来获取url地址栏的参数: ---------------------------我是分割线-------------------------------- var reg1=/([^?& ...

  6. js如何获取url参数

    匹配URL参数的正则是: var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", ...

  7. asp.net 正则获取url参数

    现在有一种场景:Url是数据库里面的,里面带有很多参数,如何获取具体参数的值呢? var uri = new Uri(pageUrl); var queryString = uri.Query; va ...

  8. Javascript 获取url参数,hash值 ,cookie

    /** * 获取请求参数 * @param key * @returns {*} */ function getRequestParameter(key){ var params = getReque ...

  9. JS动态获取 Url 参数

    此操作主要用于动态 ajax 请求 1.首先封装一个函数 GetRequest(),能动态获取到 url 问号"?"后的所有参数 , function GetRequest() { ...

随机推荐

  1. 相机标定 和 单应性矩阵H

    求解相机参数的过程就称之为相机标定. 1.相机模型中的四个平面坐标系: 1.1图像像素坐标系(u,v) 以像素为单位,是以图像的左上方为原点的图像坐标系: 1.2图像物理坐标系(也叫像平面坐标系)(x ...

  2. Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类

    A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. google protobuf service使用

    http://note.youdao.com/noteshare?id=c59aaf827878e7a3611588f3abcd3bee

  4. rename table table1 to table2;

    1. MYSQL rename table table1 to table2;

  5. win32/linux 线程 log

    原文 #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #includ ...

  6. APP的数据采集与埋点方式分析

    前言: 神策数据写过几篇分析APP前后端埋点的文章,原文在此: https://sensorsdata.cn/blog/shu-ju-jie-ru-yu-mai-dian/ http://www.wo ...

  7. LightOJ 1065 - Number Sequence 矩阵快速幂水题

    http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...

  8. js和jquery中的遍历对象和数组(forEach,map,each)

    arr[].forEach(function(value,index,array){ //do something }) 参数:value数组中的当前项,index当前项的索引,array原始数组: ...

  9. parseInt

    本文地址:http://www.cnblogs.com/veinyin/p/7647863.html 先来个简单的 console.log(parseFloat("8")); 嗯, ...

  10. oschina ios开发学习

    应该跟android版的类似,例如服务器端在oschina-prefix.pch里 #define api_news_list @"http://www.oschina.net/action ...