Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript URL、哈希或查询字符串中应该首先出现什么?_Javascript_Url_Hash_Query String - Fatal编程技术网

Javascript URL、哈希或查询字符串中应该首先出现什么?

Javascript URL、哈希或查询字符串中应该首先出现什么?,javascript,url,hash,query-string,Javascript,Url,Hash,Query String,一些在线文章说,URL中的querystring和hash没有标准,但我们正在关注不断发生的事情。所以,我的问题是,在同一个URL中使用querystring和hash的更好方法是什么 我认为问题是,如果hash跟在querystring后面,它可能会成为某些querystring数据的值,如果querystring跟在hash后面,整个querystring可能会变成hask。那么,我应该遵循什么顺序呢?这是我在JavaScript中尝试过的: window.location="alpha#a

一些在线文章说,URL中的
querystring
hash
没有标准,但我们正在关注不断发生的事情。所以,我的问题是,在同一个URL中使用querystring和hash的更好方法是什么


我认为问题是,如果hash跟在querystring后面,它可能会成为某些querystring数据的值,如果querystring跟在hash后面,整个querystring可能会变成hask。那么,我应该遵循什么顺序呢?

这是我在JavaScript中尝试过的:

window.location="alpha#abc?def=34";
console.log(window.location);
结果是:

Location {
  hash: "#abc?def=34",
  search: "",
  ...otherData
}
Location {
  hash: "#def",
  search: "?abc=34",
  ...otherData
}
然后:

window.location="alpha?abc=34#def";
console.log(window.location);
结果是:

Location {
  hash: "#abc?def=34",
  search: "",
  ...otherData
}
Location {
  hash: "#def",
  search: "?abc=34",
  ...otherData
}
显然,JavaScript不会区分#符号之后的任何内容,而哈希之前的查询字符串工作正常

因此,我们应该首先使用querystring,然后使用hash

一些在线文章说,URL中没有查询字符串和哈希的标准

要么他们错了,要么你误解了他们

查询字符串必须出现在片段标识符(您称之为哈希)之前

显示URI的格式:

它清楚地显示了查询后出现的片段

如果哈希跟随querystring,它可以成为某些querystring数据的值

不可能。
#
是一个特殊字符,指示片段的开始。要在查询字符串数据中包含一个,需要将其转义为
%23