JavaScript分割window.location.hash

jskidd3
var fullHash = window.location.hash;
// fullHash = #search?t=operator&q=Velvet

我需要将fullHash变量拆分为3个单独的值。一个值需要说“搜索”,另一个值应该说“操作员”,而最后一个值应该说“天鹅绒”。我曾尝试过多个正则表达式样式拆分,但无法弄清楚。如果有人可以帮助我写这篇文章,我将不胜感激!

阿米特·乔基(Amit Joki)

简单的解决方案:

var fullHash = window.location.hash;
    fullHash.match(/\w{3,}/g);

结果是:

["search", "operator", "Velvet"]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Javascript 使用 .hash 重定向 window.location.url

window.location.hash上的错误

window.location.hash 和 location.hash 有什么区别?

开启-window.location.hash-更改了吗?

window.location.hash始终显示为空

试图将变量传递给window.location.hash

Javascript无需滚动即可更改window.location.hash,但仍会触发CSS:target伪类

“ window.location.href”和“ window.location.hash”之间有什么区别?

编译多个hash.location

如何在不跳文档的情况下更新window.location.hash?

Asp Core 5.0 Razor Page:如何在调用 RedirectToPage() 时保留 window.location.hash

替换 window.location.hash url 中的一个字符

jQuery:如何自动将window.location.hash应用于与按钮id中相同的数字?

window.location.hash-它是什么,以及它的用例?

jQuery:根据window.location.hash将DIV类分配为“活动”类

如何将字符串添加到 window.location.hash

Javascript / Jquery window.location

使用JSm设置location.hash和location.href

如何防止$ location.hash()在#之后添加/?

从location.hash的网址中删除#

使用`window.location.hash.includes`在IE11中抛出“对象不支持属性或方法'includes'”

使用`window.location.hash.includes`在IE11中抛出“对象不支持属性或方法'includes'”

更改window.location.hash会在历史记录中创建条目,但不会影响chrome后退按钮

Javascript:window.location.search不更新?

在JavaScript中模拟window.location.href

新标签中的javascript window.location

JavaScipt window.location

将location.hash从当前URL附加到目标URL

页面根上location.hash的条件是什么?