gpt4 book ai didi

jquery location.pathname.split ("/")返回空的第一个和最后一个元素

转载 作者:行者123 更新时间:2023-12-01 02:57:07 31 4
gpt4 key购买 nike

我正在使用 var url = location.pathname.split("/") 来分割 URL。

结果的第一个和最后一个元素始终为空。谁能解释一下为什么会这样?

谢谢。

最佳答案

因为路径以/开头,并且在此之前有一个空字符串。如果路径也以/结尾,后面还会有另一个空字符串。

这与 jQuery 无关,它是简单的 JavaScript 行为。如果您想删除,可以删除 location.pathname 开头/结尾处的“/”字符,或者忽略数组中的空字符串。

关于jquery location.pathname.split ("/")返回空的第一个和最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18762585/

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