例如,当我们解析这个查询字符串时:
foo&bar=&baz=123
Firefox 对标准 URLSearchParams
类型 ( spec ) 的实现为 foo
和 bar
分配一个空字符串值:
这是否意味着 foo
和 foo=
在查询字符串中实际上是相同的?还是 Firefox 中的一个错误?
最佳答案
答案就在您发布的链接的规范中......
For each byte sequence bytes in sequences, run these substeps:
If bytes is the empty byte sequence, run these substeps for the next byte sequence.
If bytes contains a
=
, then let name be the bytes from the start of bytes up to but excluding its first=
, and let value be the bytes, if any, after the first=
up to the end of bytes. If=
is the first byte, then name will be the empty byte sequence. If it is the last, then value will be the empty byte sequence.Otherwise, let name have the value of bytes and let value be the empty byte sequence
所以... key 和 key= 是相同的...这不是一个错误。
关于javascript - "key"和 "key="URL 查询字符串之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30538760/