Function: getLocationSearchParam

getLocationSearchParam(name): string | null

从URL查询字符串中获取指定参数的值

Parameters

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

Returns

string | null

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

Description

专门处理location.search部分的参数,格式为?key=value&key2=value2

Throws

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

Example

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