HTML 形式:输出 # 作为 URL 的一部分

HTML form: output # as part of URL

如果在输入字段中输入 YZ56765ZX,表单应生成以下 URL:

http://www.example.com/quick-access/?track-code#trackingIds=YZ56765ZX

形式:

<form enctype="text/plain" action="http://www.example.com/quick-access/">
    <input type="text" name="track-code#trackingIds" id="keys" />
    <button type="submit">Search</button>
</form>

问题是我无法生成包含 # 字符的 URL。 # 将变为 %23

我认为你不能使用这些保留符号。考虑阅读 "Reserved Characters" (RFC 3986).

您仍然可以尝试 this JSFiddle

document.getElementsByTagName('form')[0].onsubmit = function() {
    this.action += '?track-code#trackingIds=' + this.keys.value;
}
<form enctype="text/plain" action="http://www.example.com/quick-access/">
    <input type="text" id="keys" />
    <button type="submit">Search</button>
</form>