gpt4 book ai didi

javascript - URL 哈希片段中的双正斜杠是否可以

转载 作者:行者123 更新时间:2023-11-28 03:43:40 26 4
gpt4 key购买 nike

我在 javascript 中从表单构建片段字符串并使用 window.location.hash 进行设置。如果用户将表单输入留空,则生成的 URL 可以是

example.com/#search/cars//blue//mazda

注意//

如果输入价格,则为

 example.com/#search/cars/20000/blue//mazda

现在一切正常。这是不好的做法吗?

最佳答案

我认为 pushState 和其他 History API 方法还处于新生阶段,标准尚未发展。作为打开最近的 W3 作品 Repurposing the Hash Sign for the New Web :

The Hash sign (#) in a URI was originally used to introduce a static "fragment identifier", but recently it is being used in many more complex ways as it is set by and interpreted by JavaScript in Web applications.

在路径名中使用双斜杠可能会违反正常行为,但散列片段可以是任意字符串。执行 typeof,您会发现它只是一个普通字符串。它不是标准的,因此可能会疏远典型的用户体验。然而,在代码方面,我认为您可以随意使用双斜杠、三斜杠或其他任何东西。

要记住的一件事是escaped characterswindow.location.hash 属性读取时被解码。

关于javascript - URL 哈希片段中的双正斜杠是否可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8529836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com