Function: getLocationHrefParam

getLocationHrefParam(name): string | null

获取URL中指定参数的值

Parameters

Name Type Description
name string 要获取的参数名称

Returns

string | null

  • 返回解码后的参数值,如果参数不存在则返回null

Description

从当前页面的URL中解析出指定参数的值,支持查询参数(?)、哈希参数(#)和锚点参数(&)

Throws

  • 当name参数不是字符串时抛出

Example

// 假设当前URL为: http://www.example.com/?id=123&name=test
getLocationHrefParam('id');  // => "123"
getLocationHrefParam('name'); // => "test"
getLocationHrefParam('none'); // => null
ON THIS PAGE