Skip to content

URL

decodeUrl

decodeUrl(needle)

url解码。

返回值:String

参数说明类型可选值默认值
needle待解码对象String
js
console.log(JW.decodeUrl('https%3a%2f%2fgithub.com%2fGHBJayce%2fj-weapons'));

encodeUrl

encodeUrl(needle)

url编码。

返回值:String

参数说明类型可选值默认值
needle待编码对象String
js
console.log(JW.encodeUrl('https://github.com/GHBJayce/j-weapons'));

getUrlParams

getUrlParams(url)

获取指定url的所有参数。

返回值:Object

参数说明类型可选值默认值
url链接String
js
console.log(JW.getUrlParams('https://api.github.com/search/repositories?q=j-weapons&per_page=1&p=1&sort=stargazers_count'));

getCurrentUrlParams

getCurrentUrlParams()

获取当前浏览器url参数。

返回值:Object

js
console.log(JW.getCurrentUrlParams());

getUrlParam

getUrlParam(url, key[, defaultVal])

获取指定url的指定参数。

返回值:Mixed

参数说明类型可选值默认值
url链接String
key参数名称String
defaultVal未设定(JW.isSet)时的默认值*
js
var url = 'https://api.github.com/search/repositories?q=j-weapons&per_page=1&p=1&sort=stargazers_count';
console.log(JW.getUrlParam(url, 'q'));
console.log(JW.getUrlParam(url, 'author', 'GHBJayce'));

getCurrentUrlParam

getCurrentUrlParam(key[, defaultVal])

获取当前浏览器url的指定参数。

返回值:Mixed

参数说明类型可选值默认值
key参数名称String
defaultVal未设定(JW.isSet)时的默认值*
js
console.log(JW.getCurrentUrlParam('q'));
console.log(JW.getCurrentUrlParam('author', 'GHBJayce'));

setUrlParams

setUrlParams(url, key[, val])

设置指定URL单个或多个参数。设置已存在的参数名称,旧值会被覆盖。

返回值:String

参数说明类型可选值默认值
url待设定参数链接*
key参数名称String | Number | Object
val参数值Undefined | String | Number
js
var url = 'https://github.com/GHBJayce/j-weapons';
console.log(JW.setUrlParams(url, 'q'));
console.log(JW.setUrlParams(url, 'author', 'GHBJayce'));
console.log(JW.setUrlParams(url, {
    author: 'GHBJayce'
}));

setCurrentUrlParams

setCurrentUrlParams(key[, val])

设置当前URL单个或多个参数。设置已存在的参数名称,旧值会被覆盖。

返回值:String

参数说明类型可选值默认值
key参数名称String | Number | Object
val参数值Undefined | String | Number
js
console.log(JW.setCurrentUrlParams('q'));
console.log(JW.setCurrentUrlParams('author', 'GHBJayce'));
console.log(JW.setCurrentUrlParams({
    author: 'GHBJayce'
}));