问题原文
原帖链接 · user58934 · CC BY-SA 3.0
I'm passing variables through the URI string, like this:
example.com?a=first&b=second
Everything works as intended, but when I pass the source code through the W3 validator, it's flagging them as errors. When I quote the variables, like this:
example.com?a='first'&b='second'
they do not get flagged. I've never seen a website do this, but is that the proper way to pass these variables? I could not find any source that recommends quoting them in the URI.
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
<a href="link.php?a=first&b=second">Click here!</a>
The only thing that might get flagged in that anchor is the unencoded &. The & should be HTML encoded. ie. & (in order to avoid potential conflict). URL parameters certainly should not be quoted as a general rule.
The URL, by its very nature, is all a "string", so quoting URL parameter values for the sake of it does not make sense, unless you explicitly needed this for your script (although this should probably be avoided, as it just adds clutter). If you quote a URL parameter value then the quotes themselves become part of the value, they do not delimit the value itself.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
