JavaScript/url:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 引言 == == location == {| class="wikitable" |- | hash || 从 <code>#</code> 开始的 URL |- | host || 主机名 + 端口号 |- | hostname || 当前 URL 的主…”
 
Kangkk​(留言 | 贡献)
第19行: 第19行:
| serach || 从 <code>?</code> 开始的 URL
| serach || 从 <code>?</code> 开始的 URL
|}
|}
== 正则 ==
<syntaxhighlight lang="javascript">
function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    };
    return null;
}</syntaxhighlight>