Skip to content
/ GB-url Public
forked from givebest/GB-url

解析 、获取、设置 window.location.search (url) 参数

License

Notifications You must be signed in to change notification settings

qinmudi/GB-url

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GB-url


简介

queryParam 获取 window.location.search 或符合规则的字符串中某个参数的值。
setParams 设置 window.location.search 或符合规则的字符串中一个或多个参数的值,并返回 ?p1=1&p2=2&p3=3

使用

获取 URL 参数值

/**
* gbUrl.queryParam(key, url);
* @param  key [要获取的参数名]
* @param  url [要解析的 URL 或者 符合规则的字符串,默认为 window.location.href]
**/

var url = 'a.html?a=1&b=2&c=3';
gbUrl.queryParam('a', url);  // 1
gbUrl.queryParam('b', url);  // 2

设置、赋值 URL 参数

/**
* gbUrl.setParams(params, url);
* @param  params [要设置、赋值的对象(key,value)]
* @param  url [要解析的 URL 或者 符合规则的字符串,默认为 window.location.href]
**/

var url = 'a.html?a=1&b=2&c=3';
gbUrl.setParams({
  a: '11111'
}, url);  // "?a=11111&b=2&c=3"


gbUrl.setParams({
  b: '2222',
  c: '3333',
  d: '4444'
}, url);  // "?a=1&b=2222&c=3333&d=4444"

License

MIT © 2017 givebest

About

解析 、获取、设置 window.location.search (url) 参数

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%