URL:修订间差异
来自康健生活
| 第13行: | 第13行: | ||
== 参数 == | == 参数 == | ||
=== 获取参数 === | === 获取参数 === | ||
假定 URL 为 <code>https://kangkk.com/404?a=2</code>。 | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
const getQuery = name => { | |||
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); | |||
const r = window.location.search.substr(1).match(reg); | |||
if (r != null) return decodeURIComponent(r[2]); | |||
return null; | |||
} | |||
console.log(getQuery('a'));</syntaxhighlight>|{{consoleout|<pre> | |||
2 | |||
</pre>}}}} | |||
== 参考 == | == 参考 == | ||