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'
}));